C# 在 WPF 中设置按钮 FlatStyle
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/697381/
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
Setting Button FlatStyle in WPF
提问by MrEdmundo
I have just been learning about how styles and control templates in WPF can affect the appearance of buttons,
我刚刚学习了 WPF 中的样式和控件模板如何影响按钮的外观,
I'm trying to set the Button's FlatStyle, in the resources I've seen I can't find anything that tells me how I can do this, in Windows Forms this is set through FlatStyle = Flat
.
我正在尝试设置按钮的 FlatStyle,在我看到的资源中,我找不到任何告诉我如何做到这一点的内容,在 Windows 窗体中,这是通过FlatStyle = Flat
.
How would one do this in WPF?
如何在 WPF 中做到这一点?
采纳答案by Kent Boogaart
The ToolBar
class defines a Style
that makes Button
s look flat. An example of using it is:
在ToolBar
类定义Style
,使Button
神色持平。使用它的一个例子是:
<Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"/>
WPF lets you completely restyle controls to make them look like whatever you want, which is why it doesn't have such a specific FlatStyle
property on the Button
control.
WPF 允许您完全重新设置控件的样式,使它们看起来像您想要的任何东西,这就是为什么它FlatStyle
在Button
控件上没有这样一个特定的属性。
回答by PhonicUK
Add the following to your Window/Page resources:
将以下内容添加到您的窗口/页面资源中:
<Style BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" TargetType="Button"></Style>
It will apply the flat style to all buttons in that styles scope.
它将平面样式应用于该样式范围内的所有按钮。