Grid Splitter and MinWidth
I am trying to set a MinWidth for my columns.
MinWidth works correctly for Column 0 but not Column 2. The splitter just keeps dragging and I can get the Column to be less than the declared MinWidth The MinWidth seems to only take effect if the Column Width has a numeric value rather than Auto.... Is there a way to get that to work with Auto or just * ??
Any ideas?
<!-- Content Area --> <Grid x:Name="ContentGrid" Grid.Row="2"> <Grid.ColumnDefinitions> <ColumnDefinition MinWidth="32" Width="260"/> <ColumnDefinition Width="8" /> <ColumnDefinition MinWidth="100" Width="*" /> </Grid.ColumnDefinitions> <!-- Navigation --> <ItemsControl Name="NavigationRegion" Regions:RegionManager.RegionName="NavigationRegion" Grid.Column="0"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Grid/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> <!-- Splitter --> <controls:GridSplitter x:Name="GridSplitter" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Center" Background="{StaticResource SplitterBackgroundColor}" Width="8" UseLayoutRounding="True" BorderThickness="1" BorderBrush="Black" Height="Auto"/> <!-- Form --> <ItemsControl x:Name="MainRegion" Grid.Column="2" Regions:RegionManager.RegionName="MainRegion"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Grid/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </Grid>
Answers
The way I fixed this is to set a MaxWidth for Column 0. When SizeChanged fires I get the MaxWidth value for Column 0 based upon the current ActualWidth
So I removed my MinWidth from Column 2 as well. Here's the modifications:
<!-- Content Area --> <Grid x:Name="ContentGrid" Grid.Row="2"> <Grid.ColumnDefinitions> <ColumnDefinition MinWidth="32" Width="260"/> <ColumnDefinition Width="8" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> ...
Then the Event setting MaxWidth
this.SizeChanged += (s, e) => { double maxWidth = this.ActualWidth / 2.0; this.ContentGrid.ColumnDefinitions[0].MaxWidth = maxWidth; }