tags:

views:

43

answers:

3

My user control has two sub-controls, a list and a detail.

  • When nothing is selected in the list, I want the list to fill the entire control
  • When something is selected, I want the list to fill the top half and the detail control the bottom half.

Dynamically changing the visibility on the detail control is easy. What I'm stuck on is how to resize the list.

A: 

Can you not just put the list inside a <Border> or a <Grid> or something and just resize that? Or if you want scrollbars you could put it inside a <ScrollViewer>.

Henrik Söderlund
How would you write the resizeing logic?
Jonathan Allen
+1  A: 

How do you change the visibility? If you put your subcontrols in a grid with the following RowDefinitions:

<Grid.RowDefinitions>
    <RowDefinition/>
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

with list in the first row and detail control in the second then setting Visibility = Collapsed of the detail control should automatically resize the list.

Stanislav Kniazev
How is the lower control supposed to know how big to make itself if you do that?
Jonathan Allen
I assumed fixed height in my answer. Do you need it to be exactly half size of the containing control? You can bind to ActualHeight property of the Grid with a converter that halves any value passed to it. Please post a sketch of what you are trying to do - it would be easier to modify it than to guess.
Stanislav Kniazev
I wasn't aware of an ActualHeight property. That could work.
Jonathan Allen
+1  A: 

Stanislav gave me an idea. Use a gird of two rows, but don't set the heigth. Instead have the upper control RowSpan across both halves of the screen.

Upper control:

Grid.RowSpan="{p:PyBinding 1 if ($[MainList.SelectedIndex] > -1) else 2}"

Lower Control:

Visibility="{p:PyBinding BooleanToVisibility($[MainList.SelectedIndex] > -1)}"
Jonathan Allen