WPF 窗体设置

 WPF 当窗体最大化时控件位置的大小调整:

View Code
 1 <Window x:Class="WpfApplication1.MainWindow"
 2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4         FontFamily="Consolas,Microsoft Yahei" FontSize="14"
 5         Title="MainWindow">
 6     <Grid>
 7         <Grid x:Name="Grid1" Margin="10">
 8             <Grid.RowDefinitions>
 9                 <!-- 将 Grid 分为5行 其中 13 作为控件间的间隙 -->
10                 <RowDefinition Height="Auto"/>
11                 <RowDefinition Height="10"/>
12                 <RowDefinition Height="*"/>
13                 <!-- 也可以用 Star -->
14                 <RowDefinition Height="10"/>
15                 <RowDefinition Height="Auto"/>
16             </Grid.RowDefinitions>
17 
18             <!-- 最上面一行放置标题和命令按钮 -->
19             <DockPanel Grid.Row="0">
20                 <!-- 位于 0 行的控件可以省略 Grid.Row="0" -->
21                 <TextBlock DockPanel.Dock="Left" Text="窗口布局" VerticalAlignment="Center"/>
22                 <!-- 在 DockPanel 中最后一个定义的元素被视为 DockPanel.Dock="Fill" -->
23                 <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right">
24                     <Button Content="提交修改" Width="90" Height="23" Name="button1"/>
25                     <TextBlock Text=" "/>
26                     <!-- 作为 Button 的分隔符 -->
27                     <Button Content="增加一列" Width="90" Height="23" Name="button2"/>
28                 </StackPanel>
29             </DockPanel>
30 
31             <DataGrid Grid.Row="2"/>
32 
33             <Label Name="label1" Grid.Row="4">
34                 <TextBlock Text="就绪"/>
35             </Label>
36         </Grid>
37     </Grid>
38 </Window>

详细知识参考: 

http://msdn.microsoft.com/zh-cn/library/ms754152.aspx

posted on 2012-05-25 11:45  ryuu  阅读(275)  评论(0编辑  收藏  举报

导航