在code-后面我怎么能覆盖由一个应用广泛的主题设置TabItem的颜色? [英] In code-behind how can I override tabitem colors set by an application-wide theme?

查看:251
本文介绍了在code-后面我怎么能覆盖由一个应用广泛的主题设置TabItem的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我改变我的TabItem的背景色有条件在code后面。这只要没有主题在App.xaml中设置工作正常。 我怎样才能改变一个TabItem的颜色(在code),同时保持应用程序范围内的主题?

I change the background color of my TabItem conditionally in code behind. This works fine as long as no theme is set in the App.xaml. How can I change colors of a TabItem (in code) while keeping an application-wide theme?

背景:

我使用的是从 Nukeation Reuxables 免费的WPF主题。会议的主题是建立在我的App.xaml的Application.Resources部分:

I'm using a free WPF theme from Nukeation Reuxables. The theme is set in the Application.Resources section of my App.xaml:

< ResourceDictionary中源=/ ReuxablesLegacy;组件/ Edge.xaml/>

我试图有条件地设置一个TabItem的背景颜色背后code:

I'm trying to conditionally set the background color of a TabItem in code behind:

MyTabItem.Background = new SolidColorBrush(Colors.Gray);

如果我删除或注释掉的App.xaml线,设置主题背景颜色的变化。为什么题材打破我的code?我改变标签颜色(如数据被加载)来显示该选项卡包含的数据。

The background color changes if I remove or comment out the App.xaml line that sets the theme. Why does the theme break my code? I'm changing the tab color (as data is loaded) to show which tabs contain data.

我知道,XAML和绑定通常用于改变颜色,但我已经试图解决方案似乎过于复杂。 <一href=\"http://stackoverflow.com/questions/6845423/wpf4-using-xaml-binding-how-can-i-visually-alert-users-that-a-tab-contains-data\">Here是寻求所有XAML和约束力的解决办法我相关的StackOverflow的问题。该给出答案只是提出我还没有找到答案,更多的问题。

I'm aware that XAML and binding are typically used to change colors, but the solutions I've attempted seem overly complex. Here is my related StackOverflow question seeking an all XAML and binding solution. The answers given just raised more questions which I haven't found answers to.

先谢谢了。

编辑:

问题不会发生更改按钮的背景时:

button1.Background =新的SolidColorBrush(Colors.Red);

按钮的颜色变化预期(当使用一个应用广泛的主题)。

The button changes color as expected (while using an application-wide theme).

推荐答案

不幸的是,这是一个简单的问题,没有简单的答案(即我迄今发现的)。同时为了满足用户不同的路径是我的最终解决方案。

Unfortunately, this is a simple problem with no simple answer (that I have found so far). Taking a different path to satisfy users was my final solution.

而不是试图改变TabItem的背景颜色我简单地改变TabItem的前景色,如果没有数据存在于灰色。我还加上空白是这样的:标签1空白,标签2空白等,这有效解决了原来的问题。 <一href=\"http://stackoverflow.com/questions/6845423/wpf4-using-xaml-binding-how-can-i-visually-alert-users-that-a-tab-contains-data/6876114#6876114\">I描述它在这里的细节。

Instead of attempting to change the TabItem Background color I simply change the TabItem Foreground color to Gray if NO data exists. I also add the word "Blank" like this: "Tab 1 Blank", "Tab 2 Blank", etc. This an effective solution to the original problem. I describe it in detail here.

这篇关于在code-后面我怎么能覆盖由一个应用广泛的主题设置TabItem的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆