我想要一个水平的StackPanel,其中包含一些文本以及一个紧贴右侧的按钮。我尝试了以下代码:
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" FontSize="14" Margin="5,0,0,0">Ahoy!</TextBlock>
<Button HorizontalAlignment="Right" Width="25" Height="25" Style="{StaticResource buttonGlassOrb}" Background="Red" />
</StackPanel>
这似乎不起作用。显然,向TextBlock添加一个margin会起作用,像这样:
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" FontSize="14" Margin="5,0,120,0">Ahoy!</TextBlock>
<Button HorizontalAlignment="Right" Width="25" Height="25" Style="{StaticResource buttonGlassOrb}" Background="Red" />
</StackPanel>
但这样做有很多不好的原因。是否有更自然的方法来完成这个任务?