我试图获得带有一些文本的水平StackPanel,然后一个按钮一直粘到右侧.我试过这个:
<StackPanel Orientation="Horizontal"> <TextBlock VerticalAlignment="Center" FontSize="14" Margin="5,0">Ahoy!</TextBlock> <Button HorizontalAlignment="Right" Width="25" Height="25" Style="{StaticResource buttonGlassOrb}" Background="Red" /> </StackPanel>
这似乎不起作用.显然,为TextBlock添加一个边距将起作用,如下所示:
<StackPanel Orientation="Horizontal"> <TextBlock VerticalAlignment="Center" FontSize="14" Margin="5,120,0">Ahoy!</TextBlock> <Button HorizontalAlignment="Right" Width="25" Height="25" Style="{StaticResource buttonGlassOrb}" Background="Red" /> </StackPanel>
但是由于种种原因这很糟糕.还有更自然的方法吗?
解决方法
就个人而言,我会使用Grid而不是StackPanel.只需添加两列,一组设置为“*”,一组设置为“Auto”,然后将TextBlock放入第一列,按钮放入第二列:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。