在WPF中为工具栏定义两种不同的样式?
我想为 ToolBar 控件制作 2 种不同的样式:一种基于黑色按钮,一种基于银色按钮。但我不知道如何将我的按钮样式应用到它自己的工具栏样式。以下仅允许按钮的一种样式:
<Style x:Key="{x:Static ToolBar.ButtonStyleKey}"
BasedOn="{StaticResource BlackButtonStyle}"
TargetType="{x:Type Button}"/>
I want to make 2 different styles for the ToolBar control: One is based on black buttons and one on silver buttons. But I can't figure out how to apply my button styles to its own toolbar styles. The following only allows one style for the buttons:
<Style x:Key="{x:Static ToolBar.ButtonStyleKey}"
BasedOn="{StaticResource BlackButtonStyle}"
TargetType="{x:Type Button}"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是否有效...我假设您一次只想要一种样式(如果您有两个工具栏并且希望每个工具栏都不同,则需要两种不同的样式和两个不同的键)
...也就是说,当您想要将样式从黑色更改为银色时,您可以在代码中获取您的资源,并将该样式的 BasedOn 属性设置为您的 SilverButtonStyle 资源吗?
Not sure if this will work or not... I'm assuming you only want one style at a time (if you had two tool bars and wanted each to be different you need two different styles with two different keys)...
that said, when you want to change the style from black to silver, can you get get your resource in code, and set the BasedOn property of that style to your SilverButtonStyle resource?