wpf - 在网格下方添加堆栈面板
问题描述
我有一个简单的表格。我想在网格下方添加一个堆栈面板(包含一个按钮)。我添加了我想要实现的图像
我的代码:
<Window x:Class="CardReader.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CardReader"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid Margin="0,0,3.4,-0.2">
<Grid.RowDefinitions >
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="146.4" />
<ColumnDefinition Width="Auto" MinWidth="244.8" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="Name" Margin="0,0,36.2,0.4" />
<TextBox Grid.Row="0" Grid.Column="1" IsReadOnly="True" Margin="6.8,0,-21.2,0.4"/>
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
BorderBrush="Black" BorderThickness="1" Grid.Row="2">
<StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Button VerticalAlignment="Bottom" Content="Save" Height="19"/>
</StackPanel>
</Border>
</Grid>
我现在得到的结果是,按钮位于第 0 列的第 1 行的网格中。我希望按钮位于底部,并填充所有宽度,就像您在图像上看到的那样
它现在的样子,这不是我想要的
解决方案
<Window x:Class="CardReader.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CardReader"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel>
<Border Margin="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Name" />
<TextBox Grid.Column="1" />
</Grid>
</Border>
<Border Margin="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Father Name" />
<TextBox Grid.Column="1" />
</Grid>
</Border>
</StackPanel>
<Border
Grid.Row="0"
Width="1"
Margin="0,0,15,0"
HorizontalAlignment="Center"
Background="Gray" />
<Button Grid.Row="1" Content="Save" Margin="20 5"/>
</Grid>
推荐阅读
- amazon-web-services - 为什么 aws s3 bucketpolicy 允许上传对象?
- c# - C#没有通过蓝牙串口发送数据
- mysql - Mysql I 参数中的存储过程
- h2 - 错误“未找到架构“information_schema”;” 在 H2 数据库上运行“向上迁移”
- influxdb - 从 Prometheus 服务器收集指标到电报
- javascript - 如何确定 CheerioElement 是否是标题
- c# - 在C#中的TabPage文本中显示下划线字母
- arrays - 检查 argv[1] 是否是逗号分隔的整数
- c# - Opayo API - 无法验证签名
- php - Symfony 5 - 在表单中使用断言表达式