Using a GridSplitter as a swiper in a listbox
I have a ListBox
with its contents stretched to fill my Window, and in it I have a grid with two columns (three, including the GridSplitter
).
I just want to be able to use the GridSplitter
like a swiper, able to hide/show any amount of either column. ie 100% left side, 50% of each, or 100% right side, etc.
I can't for the life of me make it do that though. The elements on both sides have their own size that they desire to be, and the naive *
approach doesn't allow the GridSplitter
to shrink below that size. If I use fixed column sizings I can shrink below their desired sizes, but the GridSplitter
can then run past the end width of the Window
when resizing the Window
and the content no longer stretches to fill.
Here's a XamlPad document that best illustrates my problem:
<ListBox HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Background="Red" MinWidth="200" /> <!-- simulate fixed size content /-->
<Border Background="Purple" Width="200" HorizontalAlignment="Left" />
<GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" Background="Gray"
ResizeDirection="Columns" ResizeBehavior="PreviousAndNext" />
<Border Grid.Column="2" Background="Lime" MinWidth="200" HorizontalAlignment="Stretch" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<x:Null />
</ListBox>
Most oddly this problem doesn't occur if I don't have the ListBox. It then works exactly how I desire.
Anyway, thank you anyone for any assistance, it'd all be greatly appreciated - this has been driving me nuts :)