I put two controls in a grid column and make either the first or the second control visible. Since the width of the grid column is set to auto it will resize itself according to the width of the visible child... unless I change the width of column using a grid splitter.
Now the column does not resize itself to its content anymore if I toggle the visibility of the child controls. How can I establish the original behavior?
Thanks!
EDIT:
The width property of the column is data bound to a property that is set to GridLength.Auto again (credits to Martin Moser), but Snoop tells me that this will be ignored. So the (new) question is how I can set the width of the column back to auto.
EDIT:
An example
- Start the application
- Use the checkbox to toggle the visibility of the red panel
- => Correct resizing of the first column
- Resize column with splitter
- Check / uncheck checkbox
- => No resizing of first column anymore
XAML:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300"
Width="300">
<Window.Resources>
<BooleanToVisibilityConverter x:Key="CONV_KEY"></BooleanToVisibilityConverter>
</Window.Resources>
<Grid ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0" Width="100" Background="Red"
Visibility="{Binding ElementName=_checkBox,Path=IsChecked,Converter={StaticResource CONV_KEY}}">
</DockPanel>
<DockPanel Grid.Column="0" Width="10" Background="Green" HorizontalAlignment="Left"></DockPanel>
<GridSplitter Grid.Column="1" Width="10" ResizeBehavior="PreviousAndNext"></GridSplitter>
<CheckBox x:Name="_checkBox" Grid.Column="3" VerticalAlignment="Top">Toggle</CheckBox>
</Grid>
</Window>