代码改变世界

WPF布局-Grid布局

2010-02-22 11:19  杨延成  阅读(1740)  评论(0编辑  收藏  举报
代码
 1  <Grid Height="200" Width="300" HorizontalAlignment="Left" VerticalAlignment="Center" ShowGridLines="True" Background="ForestGreen">
 2 
 3         <Grid.Resources>
 4             <Style TargetType="{x:Type Type=RowDefinition}">
 5                 <Setter Property="RowDefinition.Height" Value="60"></Setter>
 6             </Style>
 7             <Style x:Key="font">
 8                 <Setter Property="TextBlock.Foreground" Value="Red"></Setter>
 9                 <Setter Property="TextBlock.FontFamily" Value="Aharoni"></Setter>
10                 <Setter Property="TextBlock.FontSize" Value="28"></Setter>
11             </Style>
12 
13         </Grid.Resources>
14         <Grid.RowDefinitions>
15             <RowDefinition></RowDefinition>
16             <RowDefinition></RowDefinition>
17             <RowDefinition></RowDefinition>
18             <RowDefinition Height="20"></RowDefinition>
19         </Grid.RowDefinitions>
20         <Grid.ColumnDefinitions>
21             <ColumnDefinition></ColumnDefinition>
22             <ColumnDefinition></ColumnDefinition>
23             <ColumnDefinition Width="20"></ColumnDefinition>
24         </Grid.ColumnDefinitions>
25         <Button Grid.Row="0" Grid.Column="1">
26             <Image Source="Image/Desert.jpg"></Image>
27         </Button>
28         <TextBlock Padding="5" Style="{StaticResource ResourceKey=font}" TextWrapping="Wrap" HorizontalAlignment="Center" Width="100" VerticalAlignment="Center" Grid.RowSpan="2" Grid.Row="1" Grid.Column="0">
29             Hello world!
30         </TextBlock>
31     </Grid>    <Grid Height="200" Width="300" HorizontalAlignment="Left" VerticalAlignment="Center" ShowGridLines="True" Background="ForestGreen">
32 
33         <Grid.Resources>
34             <Style TargetType="{x:Type Type=RowDefinition}">
35                 <Setter Property="RowDefinition.Height" Value="60"></Setter>
36             </Style>
37             <Style x:Key="font">
38                 <Setter Property="TextBlock.Foreground" Value="Red"></Setter>
39                 <Setter Property="TextBlock.FontFamily" Value="Aharoni"></Setter>
40                 <Setter Property="TextBlock.FontSize" Value="28"></Setter>
41             </Style>
42 
43         </Grid.Resources>
44         <Grid.RowDefinitions>
45             <RowDefinition></RowDefinition>
46             <RowDefinition></RowDefinition>
47             <RowDefinition></RowDefinition>
48             <RowDefinition Height="20"></RowDefinition>
49         </Grid.RowDefinitions>
50         <Grid.ColumnDefinitions>
51             <ColumnDefinition></ColumnDefinition>
52             <ColumnDefinition></ColumnDefinition>
53             <ColumnDefinition Width="20"></ColumnDefinition>
54         </Grid.ColumnDefinitions>
55         <Button Grid.Row="0" Grid.Column="1">
56             <Image Source="Image/Desert.jpg"></Image>
57         </Button>
58         <TextBlock Padding="5" Style="{StaticResource ResourceKey=font}" TextWrapping="Wrap" HorizontalAlignment="Center" Width="100" VerticalAlignment="Center" Grid.RowSpan="2" Grid.Row="1" Grid.Column="0">
59             Hello world!
60         </TextBlock>
61     </Grid>