Guid
    This sample shows how to create and use an instance of the Grid element in Windows Presentation Foundation.
    WPF中Guid的使用方法
    1)纯xaml
WPF SDK研究 Layout(1) Grid<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="Grid Sample">
WPF SDK研究 Layout(1) Grid    
<Grid VerticalAlignment="Top" HorizontalAlignment="Left" ShowGridLines="True" Width="250" Height="100">
WPF SDK研究 Layout(1) Grid      
<Grid.ColumnDefinitions>
WPF SDK研究 Layout(1) Grid        
<ColumnDefinition />
WPF SDK研究 Layout(1) Grid        
<ColumnDefinition />
WPF SDK研究 Layout(1) Grid        
<ColumnDefinition />
WPF SDK研究 Layout(1) Grid      
</Grid.ColumnDefinitions>
WPF SDK研究 Layout(1) Grid      
<Grid.RowDefinitions>
WPF SDK研究 Layout(1) Grid        
<RowDefinition />
WPF SDK研究 Layout(1) Grid        
<RowDefinition />
WPF SDK研究 Layout(1) Grid        
<RowDefinition />
WPF SDK研究 Layout(1) Grid        
<RowDefinition />
WPF SDK研究 Layout(1) Grid      
</Grid.RowDefinitions>
WPF SDK研究 Layout(1) Grid
WPF SDK研究 Layout(1) Grid      
<TextBlock FontSize="20" FontWeight="Bold" Grid.ColumnSpan="3" Grid.Row="0">2005 Products Shipped</TextBlock>
WPF SDK研究 Layout(1) Grid      
<TextBlock FontSize="12" FontWeight="Bold" Grid.Row="1" Grid.Column="0">Quarter 1</TextBlock>
WPF SDK研究 Layout(1) Grid      
<TextBlock FontSize="12" FontWeight="Bold" Grid.Row="1" Grid.Column="1">Quarter 2</TextBlock>
WPF SDK研究 Layout(1) Grid      
<TextBlock FontSize="12" FontWeight="Bold" Grid.Row="1" Grid.Column="2">Quarter 3</TextBlock>
WPF SDK研究 Layout(1) Grid      
<TextBlock Grid.Row="2" Grid.Column="0">50000</TextBlock>
WPF SDK研究 Layout(1) Grid      
<TextBlock Grid.Row="2" Grid.Column="1">100000</TextBlock>
WPF SDK研究 Layout(1) Grid      
<TextBlock Grid.Row="2" Grid.Column="2">150000</TextBlock>
WPF SDK研究 Layout(1) Grid      
<TextBlock FontSize="16" FontWeight="Bold" Grid.ColumnSpan="3" Grid.Row="3">Total Units: 300000</TextBlock>
WPF SDK研究 Layout(1) Grid    
</Grid>
WPF SDK研究 Layout(1) Grid
</Page>

    注意到,WPF中的Grid,很像HTML中的table。
            先定义列,再定义行,Grid中的每个元素,其属性都要指定Grid.Column和Grid.Row。对于合并行/列,则要指定Grid.ColumnSpan或RowSpan

    2)纯cs代码
    上述xaml代码完全可以使用纯cs实现,具体实现见Sample代码

相关文章: