Grid.IsSharedSizeScope Attached Property
Gets or sets a value that indicates that multiple Grid elements are sharing size information.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
<object Grid.IsSharedSizeScope="bool" .../>
Property Value
Type: System.Booleantrue if this instance of Grid is sharing size properties with another Grid; otherwise, false. The default value is false.
Columns and rows participating in size sharing do not respect Star sizing. In this scenario, Star sizing is treated as Auto.
Grid size sharing does not work if IsSharedSizeScope is set to true within a resource template, and a SharedSizeGroup is defined outside of that template.
The following code examples demonstrate how to use the IsSharedSizeScope property in Extensible Application Markup Language (XAML) and code.
...
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top"> <Button Click="setTrue" Margin="0,0,10,10">Set IsSharedSizeScope="True"</Button> <Button Click="setFalse" Margin="0,0,10,10">Set IsSharedSizeScope="False"</Button> </StackPanel> <StackPanel Orientation="Horizontal" DockPanel.Dock="Top"> <Grid ShowGridLines="True" Margin="0,0,10,0"> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="FirstColumn"/> <ColumnDefinition SharedSizeGroup="SecondColumn"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" SharedSizeGroup="FirstRow"/> </Grid.RowDefinitions> <Rectangle Fill="Silver" Grid.Column="0" Grid.Row="0" Width="200" Height="100"/> <Rectangle Fill="Blue" Grid.Column="1" Grid.Row="0" Width="150" Height="100"/> <TextBlock Grid.Column="0" Grid.Row="0" FontWeight="Bold">First Column</TextBlock> <TextBlock Grid.Column="1" Grid.Row="0" FontWeight="Bold">Second Column</TextBlock> </Grid> <Grid ShowGridLines="True"> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="FirstColumn"/> <ColumnDefinition SharedSizeGroup="SecondColumn"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" SharedSizeGroup="FirstRow"/> </Grid.RowDefinitions> <Rectangle Fill="Silver" Grid.Column="0" Grid.Row="0"/> <Rectangle Fill="Blue" Grid.Column="1" Grid.Row="0"/> <TextBlock Grid.Column="0" Grid.Row="0" FontWeight="Bold">First Column</TextBlock> <TextBlock Grid.Column="1" Grid.Row="0" FontWeight="Bold">Second Column</TextBlock> </Grid> </StackPanel> <TextBlock Margin="10" DockPanel.Dock="Top" Name="txt1"/>
...
Events defined in Extensible Application Markup Language (XAML) are handled using code.
private void setTrue(object sender, System.Windows.RoutedEventArgs e) { Grid.SetIsSharedSizeScope(dp1, true); txt1.Text = "IsSharedSizeScope Property is set to " + Grid.GetIsSharedSizeScope(dp1).ToString(); } private void setFalse(object sender, System.Windows.RoutedEventArgs e) { Grid.SetIsSharedSizeScope(dp1, false); txt1.Text = "IsSharedSizeScope Property is set to " + Grid.GetIsSharedSizeScope(dp1).ToString(); }
More Code
| How to: Create a Complex Grid | This example shows how to use a Grid to create layout that looks like a monthly calendar. |
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.