2017-10-10 53 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> 

基本上我增加了第三個欄,搬遷前兩項進入前兩列用自己的寬度指數和第三列專爲按鈕。