2017-10-10 51 views
0

XAML为UWP应用程序(我的第一次真正的尝试)控制在堆栈面板中未对齐

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

堆栈面板占用自己的一排网格。

在堆叠面板中,两个按钮没有对齐到右侧边框。他们在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

+0

不是在按钮上设置'Horizo​​ntalAlignment ='Right'',而是在'StackPanel'上设置它。 – AVK

+0

这只是将整个组向右侧移动,留下了一个很大的缺口 – VinceP1974

+0

用'Width *'将另一列添加到网格并将TextBox移动到该列。最后一列应该只包含您想要移动到右侧的按钮。 – AVK

回答

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> 

基本上我增加了第三个栏,搬迁前两项进入前两列用自己的宽度指数和第三列专为按钮。