#425 – SharedSizeGroup Allows Sharing Column Sizes Across Different Grids
November 8, 2011 3 Comments
You can use the SharedSizeGroup property of a ColumnDefinition to lead to consistent column sizes in a ListBox with a data template. This works because each entry in the list has its own instance of a Grid and the column sizes are being shared across different grids.
As a more general example, we can share column sizes across two Grid controls hosted in the same window.
<StackPanel Grid.IsSharedSizeScope="True"> <Label Content="First grid:" /> <Grid Margin="10" ShowGridLines="True" Background="AliceBlue"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" SharedSizeGroup="A"/> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Label Grid.Column="0" Content="{Binding Thing1}"/> </Grid> <Label Content="Second grid:" /> <Grid Margin="10" ShowGridLines="True" Background="AliceBlue"> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition Width="Auto" SharedSizeGroup="A"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Label Grid.Column="1" Content="{Binding Thing2}"/> </Grid> <Button Margin="10" Content="Change Thing1" Click="Button_Click" /> </StackPanel>
We share size between the first column in the first grid and the second column in the second grid, since they use the same value for SharedSizeGroup.
After adding characters to Thing1: