wpf 如何让按钮内容在WPF中垂直显示?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15795136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:27:32  来源:igfitidea点击:

How to make the button content display vertically in WPF?

wpfbuttonuser-interface

提问by fork123x

Recently I installed Visual Studio 2010 and I find that the content of the sidebar button goes vertically like the below image

最近我安装了 Visual Studio 2010,我发现侧边栏按钮的内容像下图一样垂直

Screenshot of vertical text for VS2010

VS2010 竖排文字截图

My question is: is there a simple way to achieve this effect in WPF?

我的问题是:有没有一种简单的方法可以在 WPF 中实现这种效果?

回答by Adolfo Perez

Very easy, use LayoutTransformand RotateTransform:

非常简单,使用LayoutTransformRotateTransform

<ToggleButton Content="Members Info" HorizontalAlignment="Right" 
              Click="btn_MembersInfo_Click">         
    <ToggleButton.LayoutTransform>
        <RotateTransform Angle="-90" />
</ToggleButton.LayoutTransform>
</ToggleButton>

回答by paparazzo

Will need to adjust Width Height and Center

需要调整宽度高度和中心

<Button Content="RotatedButton" Width="200" Height="100">
    <Button.RenderTransform>
        <RotateTransform CenterX="0" CenterY="0" Angle="90" />
    </Button.RenderTransform>
</Button>