Grid.IsSharedSizeScope Grid.IsSharedSizeScope Grid.IsSharedSizeScope Attached Property

定义

获取或设置一个值,该值指示多个 Grid 元素共享大小信息。Gets or sets a value that indicates that multiple Grid elements are sharing size information.

see GetIsSharedSizeScope, and SetIsSharedSizeScope
see GetIsSharedSizeScope, and SetIsSharedSizeScope
see GetIsSharedSizeScope, and SetIsSharedSizeScope

示例

下面的代码示例演示如何使用IsSharedSizeScope中的属性可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML)和代码。The following code examples demonstrate how to use the IsSharedSizeScope property in 可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML) and code.

<DockPanel Name="dp1" Grid.IsSharedSizeScope="False" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10">

......

<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"/>

......

在定义的事件可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML)通过使用代码进行处理。Events defined in 可扩展应用程序标记语言 (XAML)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();
}
Private Sub setTrue(ByVal sender As Object, ByVal args As RoutedEventArgs)

    Grid.SetIsSharedSizeScope(dp1, True)
    txt1.Text = "IsSharedSizeScope Property is set to " + Grid.GetIsSharedSizeScope(dp1).ToString()
End Sub

Private Sub setFalse(ByVal sender As Object, ByVal args As RoutedEventArgs)

    Grid.SetIsSharedSizeScope(dp1, False)
    txt1.Text = "IsSharedSizeScope Property is set to " + Grid.GetIsSharedSizeScope(dp1).ToString()
End Sub

注解

共享大小的行和列不遵从Star大小调整。Columns and rows participating in size sharing do not respect Star sizing. 在此方案中,Star调整大小将被视为AutoIn this scenario, Star sizing is treated as Auto.

如果网格大小共享无法工作IsSharedSizeScope设置为true内的资源模板,和一个SharedSizeGroup该模板的外部定义。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.

依赖项属性信息Dependency Property Information

标识符字段Identifier field IsSharedSizeScopeProperty
元数据属性设置为 trueMetadata properties set to true None

适用于