views:

142

answers:

1

Here is the code I have and wondered how I could completely rollup the stack, expander and objects within it to push all objects below it to take up the space left after rolling up the upper stack and objects. My current code is below:

<Grid>
 <StackPanel Margin="8,8,0,0" VerticalAlignment="Top" Height="225">
  <Expander Header="Expander">
   <Grid Height="201">
    <ListBox HorizontalAlignment="Left" Margin="103,63,0,38" Width="100">
     <ListBoxItem Content="Brown"/>
     <ListBoxItem Content="Red"/>
     <ListBoxItem Content="Green"/>
     <ListBoxItem Content="Yellow"/>
    </ListBox>
   </Grid>
  </Expander>
 </StackPanel>
 <StackPanel Margin="0,0,0,8" VerticalAlignment="Bottom" Height="221">
  <Expander Header="Expander">
   <Grid Height="194">
    <ListBox Margin="177,21,213,73">
     <ListBoxItem Content="Gold"/>
     <ListBoxItem Content="Silver"/>
     <ListBoxItem Content="Platinum"/>
     <ListBoxItem Content="Palladium"/>
    </ListBox>
   </Grid>
  </Expander>
 </StackPanel>

</Grid>
+1  A: 

If I've understood correctly what you want to do, you can do this using star sizing in your Grid. Star sizing tells the Grid to use all remaining available size (divvied up in proportion if multiple rows/columns are star-sized). Thus:

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>
  <StackPanel Margin="8,8,0,0" VerticalAlignment="Top" Height="225" Grid.Row="0">
    <!-- first Expander here -->
  </StackPanel>
  <StackPanel Margin="0,0,0,8" VerticalAlignment="Bottom" Grid.Row="1">
    <!-- second Expander here -->
  </StackPanel>
</Grid>

Note the Grid.Row attached properties.

Now when you make set the first StackPanel's visibility to Collapsed, it takes up no height. So in turn the first row of the Grid collapses to zero heigh. So the entire height of the grid is devoted to the second row, which means that the entire height of the grid is given over to the second StackPanel and its contents.

Is this the outcome you're after? I may have misunderstood the question... if so please leave a comment and I will update or delete.

itowlson