0

I've inherited a silverlight app that now needs extending. The app sits on a map and originally had 1 text block item and a single accordion control of options. This has been extended so that the text block becomes an accordion item and further accordion item has been added with 2 sets of controls.

So my plan started along the lines of

<accordionMain>
  <accordionMainItem1>
    <accordion1>
      <accordion1Item>
        <controls>
      </accordion1Item>
      <accordion1Item2>
        <controls>
      </accordion1Item2>
    </accordion1>
  <accordionMainItem1>
  <accordionMainItem2>
    <accordion2>
      <accordion2Item>
        <controls>
      </accordion2Item>
      <accordion2Item2>
        <controls>
      </accordion2Item2>
    </accordion2>
  <accordionMainItem2>
</accordionMain>

This would hopefully give me the structure that I needed to add controls to.

Being new to Silverlight but having done a bit of XAML I made some progress but have hit a problem.

The StackPanel and Canvas that the whole thing sits on does not resize automatically as I would like. I'm unsure how to go about this but have tried Height="Auto" with no luck. What I would like would be when the 2nd accordion is expanded the panel and border underneath auto size as needed.

I have attached the full XAML here

SteveB
  • 1,474
  • 1
  • 13
  • 21

1 Answers1

1

Personally, I avoid the StackPanel for non-trivial layout of controls. I find a Grid is much more flexible when it comes to filling available space and resizing, which is normally what I want when designing an interface that will grow and shrink.

So my first step with your example would be to define a couple of rows for your grid, and place your expanding elements into a row each. Looking back at your example I see there is actually only one expanding thing: the AccordianMain, so make sure that is in a Row where Height="Auto".

What are you using the Canvas for incidentally? And why is the Grid that contains the accordians on the Canvas, and the only item in the StackPanel the Canvas?

Try and simplify your layout, I don't see why your inner Grid can't be directly placed into your Border and so can't see what the StackPanel or Canvas are bringing to the party. But maybe I'm missing something.

Mashton
  • 6,037
  • 2
  • 25
  • 35
  • Hi thanks for the reply. You're not missing anything - I copied the existing bunch of controls and wrapped them in an AccordionItem of the main accordion. My intention was to then remove the 'extra' control I didn't need. In doing that I also copied all of the canvas and stack panels those controls were sitting on. I'm currently removing them to simplify matters. – SteveB Sep 08 '14 at 12:22
  • I think removing the `Canvas` will solve your problems. The Canvas uses absolute positioning, which doesn't take into account resizing. In nearly all cases you can get a nice dynamic size layout just from clever use of the `Grid`. – Mashton Sep 08 '14 at 12:57
  • Your suggestion about removing the canvas was spot on. I also applied the style fix here http://stackoverflow.com/questions/3680985/how-to-get-accordion-region-to-expand-vertically-to-dynamic-content and that fixed an issue with the nested accordions not drawing properly. Many thanks. – SteveB Sep 08 '14 at 21:33