views:

1199

answers:

1

I've got a grid that has 7 rows in it. Row 0 is a group of 2 buttons Row 1 is a ListBox of objects Row 2 is a group of 3 buttons Row 3 is a group of 2 buttons Row 4 is where my GridSplitter lives Row 5 is a group of 2 buttons Row 6 is a ListBox of objects

I want the GridSplitter to slide up and down, resizing each of the two ListBox's. I've got it living in its own row now, and when i Slide it, it freeze's when it gets to the top of row 4 (its own row) and simply creates white space while it expans row 4 downwards.

I just need that splitter to slide up and down and resize each ListBox. Currently those ListBoxes have vertical scrolling bars if they get too big for their view.

any ideas?

+3  A: 

Here's some XAML that shows how to use a GridSplitter as you've described:

<Grid VerticalAlignment="Stretch">  
  <Grid.RowDefinitions>
    <RowDefinition Height="10" />
    <RowDefinition Height="10" />
    <RowDefinition Height="10" />
    <RowDefinition Height="10" />
    <RowDefinition Height="10" />
    <RowDefinition Height="10" />
    <RowDefinition Height="*" />
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>

  <Rectangle Grid.Row="0" Fill="Red" />
  <Rectangle Grid.Row="1" Fill="Orange" />
  <Rectangle Grid.Row="2" Fill="Yellow" />
  <Rectangle Grid.Row="3" Fill="Green" />
  <Rectangle Grid.Row="4" Fill="Blue" />
  <Rectangle Grid.Row="5" Fill="LightBlue" />

  <ListBox Grid.Row="6" Background="Indigo">
    <ListBoxItem>Hello</ListBoxItem>
    <ListBoxItem>World</ListBoxItem>
  </ListBox>

  <GridSplitter Grid.Row="7" Height="5" Background="Gray"
                VerticalAlignment="Top" HorizontalAlignment="Stretch" />

  <ListBox Grid.Row="7" Background="Violet" Margin="0,5,0,0">
    <ListBoxItem>Hello</ListBoxItem>
    <ListBoxItem>World</ListBoxItem>
  </ListBox>
</Grid>

Avoid putting the GridSplitter in it's own row. Put it inside an existing row, and set it's alignment to the top (or bottom, if in the upper cell), stretched horizontally. Note how I've set it's height to 5, and then given an upper margin of 5 to the second ListBox so that neither element hides any part of the other.

Hope that helps.

Drew Noakes
I tried this with my code, and it doesn't seem to work. The gridsplitter just sits idle and won't move up or down. I have 3 rows with height set to Auto: one row with a stackpanel of elements, one row with a gridsplitter, and one row with another stackpanel of elements. any ideas why it wont scroll?
Shafique
Hi Shafique. There must be something different about the way you've implemented the GridSplitter then. Try copying all of the above XAML and pasting as the child element of the Page element in Kaxaml. You will see that the GridSplitter works as expected. From there, you can migrate the XAML to more closely match what you have and find the exact issue. http://www.kaxaml.com
Drew Noakes
I've seen some stupid examples out there where they have VerticalAlighment="Center". That doesn't work. I'm not sure when it would but it didn't for me. Making it top fixed it. I'm still not quite sure how it works. I much prefered the simplicity of SplitterPanel but oh well...
Simon_Weaver