WPF 选项卡控件:设置选项卡颜色?
我的 WPF 应用程序中有一个 TabControl
,它使用 WPF 选项卡控件的默认颜色。换句话说,活动选项卡是白色的,非活动选项卡是银色的。我通过设置 TabControl
对象的 Background
属性,将所有选项卡页的 Background
颜色更改为米色,但它没有不更改选项卡颜色,仅更改客户区。因此,我最终得到了一个活动选项卡,其中有一个米色客户区和一个白色选项卡。
我想设置选项卡Color
以匹配客户区域,以便整个页面是米色的。我该怎么做呢?谢谢。
I have a TabControl
in my WPF application that uses the default colors for the WPF tab control. In other words, the active tab is white, and the inactive tabs are silver. I have changed the Background
color of all of the tab pages to Beige, by setting the Background
property of the TabControl
object, but it doesn't change the tab color, only the client area. So, I have ended up with an active tab that has a beige client area and a white tab.
I would like to set the tab Color
to match the client area, so that the entire page is beige. How would I do that? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我的一个项目中的选项卡项样式的示例。抱歉有些不相关的代码,我相信您会从中提取您需要的内容。
希望有帮助。
Here is an example of tab item style from one of my projects. Sorry for some irrelevant code, I'm sure you will extract what you need from it.
Hope it helps.
我想出了解决办法。我将把莱万诺夫的答案选为正确的答案,以感谢他的帮助。
本质上,该修复是对
TabItem
控件模板的一行更改。从普通TabItem
控件模板的副本开始,并将控件模板设置为针对TabItem
类型的所有控件。找到IsSelected
触发器,并将其更改为以下内容:Bd
是Border
控件,用于设置选项卡区域的边框和背景。TabItem
。此标记告诉 WPF 将Bd
Background
属性绑定到相对源。在本例中,相对源是托管TabItem
的TabControl
的Background
属性。因此,当您设置TabControl
的Background
属性时,颜色将流到所有TabItem
控件的选项卡区域托管在TabControl
中。以下是我在 Blend 3 中创建的演示的完整标记:
I worked out the solution. I am going to leave levanovd's answer selected as the correct one, in appreciation for his help.
Essentially, the fix is a one-line change to the
TabItem
control template. Start with a copy of the normalTabItem
control template, and set the control template to target all controls of typeTabItem
. Find theIsSelected
trigger, and change it to the following:Bd
is theBorder
control that sets the border and background for the tab area of aTabItem
. This markup tells WPF to bind theBd
Background
property to a relative source. In this case, the relative source is theBackground
property of theTabControl
that hosts theTabItem
. As a result, when you set theBackground
property of theTabControl
, the color will flow through to the tab area of all of theTabItem
controls hosted in theTabControl
.Here is the complete markup for a demo that I created in Blend 3: