周末充电之WPF(二 ) .窗口的布局
2024-08-29 07:30:37
登录窗口布局:[ 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> ,其实这两个是相同的。
最新文章
- Android常用组件之ListView
- 学习C++.Primer.Plus 11 使用类
- oracle的分析函数over 及开窗函数
- HTML5学习之WebSocket通讯(六)
- ISODATA算法
- android 关于Location of the Android SDK has not been setup in the preferences的解决方法
- Swift数字类型之间的转换
- 动态规划——C编辑最短距离
- shopnc 导出Excel数据问题实例 &;&; ajax 获取当前值并传递
- 那些年搞不懂的";协变";和";逆变";
- LeetCode Javascript实现 100. Same Tree 171. Excel Sheet Column Number
- 后端开发者的Vue学习之路(一)
- linuxmint 搜狗输入法安装
- vue项目sql图片动态路径引用问题
- library之目录
- (转)CS域和PS域
- BIO、NIO和AIO的区别(简明版)
- 如何使用 MasterPage
- playbook-拓展
- Android UI-实现底部切换标签(fragment)