Horizo​​ntalContentAlignment不会出现

时间:2015-06-17 09:17:13

标签: wpf xaml

我的.xaml中有以下代码:

<StackPanel
         Orientation="Horizontal"
         DockPanel.Dock="Top" Background="Yellow" 
         HorizontalAlignment="Right" VerticalAlignment="Top"
         Margin="0,2,2,0"
         Name="MainButtonsPanel"
         Width="100" >
   <Button Name="ButtonSaveChanges" 
         Background="LightGray"
         Width="100"
         Height="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth}"
         Command="{Binding MyCommand}"
         CommandParameter="{Binding}" Visibility="Visible" />
     <Button Name="ButtonEdit" 
         Background="Gray"
         Width="100"
        Height="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth}"
        Command="{Binding MyCommand}" 
        CommandParameter="{Binding}" />
</StackPanel>

它在运行时看起来像这样:

enter image description here

我希望灰色方块与右边对齐。我尝试使用VerticalContentAlignment,但在我编写它时,它并没有出现在我的.xaml元素中...

关于如何实现这一点的任何想法?

1 个答案:

答案 0 :(得分:1)

StackPanel有一个名为“FlowDirection”的属性。这是你在找什么?

<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Background="Yellow" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,2,2,0" Name="MainButtonsPanel" Width="400" FlowDirection="RightToLeft">

enter image description here