我正在尝试使用一些文本获得水平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>
Run Code Online (Sandbox Code Playgroud)
哪个似乎不起作用.显然,为TextBlock添加一个边距将起作用,如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
但是由于种种原因这很糟糕.还有更自然的方法吗?