在WPF中为工具栏定义两种不同的样式?

发布于 2024-09-09 04:09:30 字数 265 浏览 4 评论 0原文

我想为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百变从容 2024-09-16 04:09:31

不确定这是否有效...我假设您一次只想要一种样式(如果您有两个工具栏并且希望每个工具栏都不同,则需要两种不同的样式和两个不同的键)

...也就是说,当您想要将样式从黑色更改为银色时,您可以在代码中获取您的资源,并将该样式的 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文