繁体   English   中英

在网格下方添加堆栈面板

[英]Add stackpanel below grid

我有一个简单的表格。 我想在网格下面添加一个堆栈面板(包含一个按钮)。 我添加了一张我想要实现的图像

我的代码:

<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>

<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>

似乎您希望两列带有属性名称和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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM