登录窗口布局:[ Grid 布局 -Grid.RowDefinitions / Grid.ColumnDefinitions]
代码如下:
<Window x:Class="login.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="200" Width="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--默认在第0行0列-->
<!--HorizontalAlignment:水平方向对齐 VerticalAlignment:垂直方向对齐-->
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="username:"></TextBlock>
<TextBox Grid.Column="1" Name="uid" Margin="5"></TextBox>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="password:" Grid.Row="1"></TextBlock>
<PasswordBox Grid.Column="1" Name="pwd" Margin="5" Grid.Row="1"></PasswordBox>
<Button Content="login" Grid.Row="2" Margin="10" Click="Button_Click_1"></Button>
<Button Content="cancer" Grid.Row="2" Margin="10" Grid.Column="1"></Button>
</Grid>
</Window>
Menu / ToolBar 布局:
<Window x:Class="toolbar.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="打开">
<MenuItem Header="删除"></MenuItem>
</MenuItem>
<MenuItem Header="编辑"></MenuItem>
</Menu>
<ToolBar DockPanel.Dock="Top">
<Button>
<Button.Content>
<Image Source="s.png" Width="16"></Image>
</Button.Content>
</Button> <Button>
<Button.Content>
<Image Source="c.png" Width="16"></Image>
</Button.Content>
</Button>
<CheckBox>
<Image Source="cc.png" Width="16"></Image>
</CheckBox>
</ToolBar>
<TextBox DockPanel.Dock="Bottom"></TextBox>
</DockPanel>
</Grid>
</Window>
如上代码你会发现在为控件设置图标按钮时,会有两种写法 xx.Content 或者直接去除写 <Image...></Image> ,其实这两个是相同的。