父容器 设置属性 Grid.IsSharedSizeScope="True"  

在设置某行或者某列 设置共享属性SharedSizeGroup;

 

<DockPanel Grid.IsSharedSizeScope="True">
        <DockPanel.Resources>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="Margin" Value="5,3" />
            </Style>
        </DockPanel.Resources>
        <Grid DockPanel.Dock="Top">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" SharedSizeGroup="Location" />
                <ColumnDefinition Width="Auto" SharedSizeGroup="Rank" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Border Grid.Column="0" Grid.Row="0" BorderThickness="1"
                    Background="LightGray" BorderBrush="Gray">
                <TextBlock>Title</TextBlock>
            </Border>
            <Border Grid.Column="1" Grid.Row="0" BorderThickness="1"
                    Background="LightGray" BorderBrush="Gray">
                <TextBlock>Location</TextBlock>
            </Border>
            <Border Grid.Column="2" Grid.Row="0" BorderThickness="1"
                    Grid.ColumnSpan="2"
                    Background="LightGray" BorderBrush="Gray">
                <TextBlock>Rank</TextBlock>
            </Border>

            <FrameworkElement Grid.Column="3"
               Width="{DynamicResource {x:Static SystemParameters.ScrollWidthKey}}" />

        </Grid>
        <ScrollViewer>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" SharedSizeGroup="Location" />
                    <ColumnDefinition Width="Auto" SharedSizeGroup="Rank" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <TextBlock Grid.Column="0" Grid.Row="0">
                    Mastering Visual Studio .NET
                </TextBlock>
                <TextBlock Grid.Column="1" Grid.Row="0">
                    O'Reilly Media, Inc.
                </TextBlock>
                <TextBlock Grid.Column="2" Grid.Row="0">1</TextBlock>

                <TextBlock Grid.Column="0" Grid.Row="1">IanG on Tap</TextBlock>
                <TextBlock Grid.Column="1" Grid.Row="1">The Internet</TextBlock>
                <TextBlock Grid.Column="2" Grid.Row="1">2</TextBlock>
            </Grid>
        </ScrollViewer>
    </DockPanel>s

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐