我有一个简单的表格。我想在网格下面添加一个堆栈面板(包含一个按钮)。我添加了一张我想要达到的目标的图像
我的代码:
<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行的网格中。我希望该按钮位于底部,并填充所有宽度,就像您在图像上看到的那样
它当前的样子,这不是我想要的
答案 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>
答案 1 :(得分: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 Margin="0,0,3.4,-0.2">
<Grid.RowDefinitions >
<RowDefinition Height="*" />
<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="1" Grid.Column="0" Grid.ColumnSpan="2">
<StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Button VerticalAlignment="Bottom" Content="Save" Height="19"/>
</StackPanel>
</Border>
</Grid>
答案 2 :(得分:0)
似乎您希望两列包含属性名称和texbox的列,因此我建议您:
<Grid >
<Grid.RowDefinitions >
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel>
<!-- Copy this block for adding new lines -->
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<Label Content="Name" Width="100"/>
<TextBox IsReadOnly="True" Width="400"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<Label Content="Surname" Width="100"/>
<TextBox IsReadOnly="True" Width="400"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<Label Content="Whatever" Width="100"/>
<TextBox IsReadOnly="True" Width="400"/>
</StackPanel>
</StackPanel>
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
BorderBrush="Black" BorderThickness="1" Grid.Row="2" Grid.ColumnSpan="2" >
<Grid>
<Button VerticalAlignment="Bottom" Content="Save" Height="19"/>
</Grid>
</Border>
</Grid>