学海无涯

导航

共享尺寸组 SharedSizeGroup

整体布局由DockPanel  定义,使用附加的Dock.Top属性将标头Grid定位在顶部,并
允许ScrollViewer填充剩余空间。
 
 
 1  <DockPanel Grid.IsSharedSizeScope="True">
 2         <DockPanel.Resources>
 3             <Style TargetType="TextBlock">
 4                 <Setter Property="Margin" Value="5,3" />
 5             </Style>
 6         </DockPanel.Resources>
 7         <Grid DockPanel.Dock="Top">
 8             <Grid.ColumnDefinitions>
 9                 <ColumnDefinition Width="*" />
10                 <ColumnDefinition Width="Auto" SharedSizeGroup="Location" />
11                 <ColumnDefinition Width="Auto" SharedSizeGroup="Rank" />
12                 <ColumnDefinition Width="Auto" />
13             </Grid.ColumnDefinitions>
14             <Grid.RowDefinitions>
15                 <RowDefinition Height="Auto" />
16             </Grid.RowDefinitions>
17             <Border Grid.Column="0" Grid.Row="0" BorderThickness="1"
18  Background="LightGray" BorderBrush="Gray">
19                 <TextBlock>Title</TextBlock>
20             </Border>
21             <Border Grid.Column="1" Grid.Row="0" BorderThickness="1"
22  Background="LightGray" BorderBrush="Gray">
23                 <TextBlock>Location</TextBlock>
24             </Border>
25             <Border Grid.Column="2" Grid.Row="0" BorderThickness="1"
26  Grid.ColumnSpan="2"
27  Background="LightGray" BorderBrush="Gray">
28             </Border>
29             <TextBlock Grid.Column="2" Grid.Row="0">Rank</TextBlock>
30             <FrameworkElement Grid.Column="3"
31  Width="{DynamicResource
32  {x:Static SystemParameters.VerticalScrollBarWidthKey}}" />
33         </Grid>
34         <ScrollViewer>
35             <Grid>
36                 <Grid.ColumnDefinitions>
37                     <ColumnDefinition Width="*" />
38                     <ColumnDefinition Width="Auto" SharedSizeGroup="Location" />
39                     <ColumnDefinition Width="Auto" SharedSizeGroup="Rank" />
40                 </Grid.ColumnDefinitions>
41                 <Grid.RowDefinitions>
42                     <RowDefinition Height="Auto" />
43                     <RowDefinition Height="Auto" />
44                 </Grid.RowDefinitions>
45                 <TextBlock Grid.Column="0" Grid.Row="0" Text="Programming WPF" />
46                 <TextBlock Grid.Column="1" Grid.Row="0" Text="O'Reilly Media, Inc." />
47                 <TextBlock Grid.Column="2" Grid.Row="0">1</TextBlock>
48                 <TextBlock Grid.Column="0" Grid.Row="1">IanG on Tap</TextBlock>
49                 <TextBlock Grid.Column="1" Grid.Row="1">The Internet</TextBlock>
50                 <TextBlock Grid.Column="2" Grid.Row="1">2</TextBlock>
51             </Grid>
52         </ScrollViewer>
53     </DockPanel>

 

posted on 2023-01-07 13:20  宁静致远.  阅读(157)  评论(0编辑  收藏  举报