控制未在堆栈面板中对齐

时间:2017-10-10 16:10:31

标签: uwp-xaml

UWP应用程序的XAML(我的第一个真正的尝试)

我在网格中有一个堆叠面板,方向是水平的。我想按顺序显示一个按钮,一个文本块和另外两个按钮。

堆栈面板占据了自己的网格行。

在堆叠面板中,两个按钮未对齐到右侧边框。他们有点像75%的位置。使用Horizo​​ntalOrientation属性在这两个按钮标记中没有区别。

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"  />
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
<StackPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
        <Button x:Name="btnShow" Margin="0,0,5,0">Show</Button>
            <TextBlock HorizontalAlignment="Stretch">Nothing searched for yet</TextBlock>
            <Button x:Name="btnLeft" HorizontalAlignment="Right" Margin="5,0,5,0">&lt;</Button>
            <Button x:Name="btnRight"  HorizontalAlignment="Right">></Button>


        </StackPanel></Grid></Grid>

enter image description here

1 个答案:

答案 0 :(得分:0)

这应该符合您的要求。

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"  />
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Button x:Name="btnShow" Margin="0,0,5,0" 
                Content="Show" Grid.Row="3" />
        <TextBlock HorizontalAlignment="Stretch" Text="Nothing searched for yet" 
                   Grid.Column="1" Grid.Row="3" VerticalAlignment="Center" />
        <StackPanel Grid.Row="3" Grid.Column="2" Orientation="Horizontal" >
            <Button x:Name="btnLeft" Margin="5,0" Content="&lt;" />
            <Button x:Name="btnRight" Content=">" />
        </StackPanel>
    </Grid>
</Grid>

基本上我添加了第三列,将前两个项目移动到前两列中,使用自己的宽度索引和第三列专门用于按钮。