我可以得到一个WPF列表框,以继承父元素刷? [英] Can I get a WPF ListBox to inherit brushes from parent element?

查看:349
本文介绍了我可以得到一个WPF列表框,以继承父元素刷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WPF窗口的前台刷设置为从资源字典中的画笔,我想在窗口中的所有文本有这个颜色,所以我不碰前台刷什么都重要。

My WPF window has its foreground brush set to a brush from a resource dictionary, and I want all text in the window to have this color, so I don't touch the foreground brush in anything else.

文本框,使色彩
的TextBlocks获得颜色
按钮,使色彩

Textboxes get the color
Textblocks get the color
Buttons get the color

列表框没有得到的颜色,所以也不做他们的内容。

Listboxes do not get the color, and so neither do their contents.

有没有什么办法让一个列表框的行为类似于在这方面的其他控件?

Is there any way to get a Listbox to behave like the other controls in this respect?

假设没有,并认为这是由设计,是什么道理呢?

Assuming not, and that this is by design, what is the rationale?

看来我的问题不够清楚。

It seems my question is not clear enough.

我知道如何创建样式和资源,并将其应用到列表框 ES;我不知道为什么我要做到这一点的某些控件,当我的没有的需要为他人 - 为什么一些继承性和别人不 - ,以及是否有办法使他们所有继承以相同的方式

I understand how to create styles and resources and apply them to ListBoxes; I'm wondering why I need to do this for certain controls when I do not need to for others -- why some inherit properties and others do not -- and whether there is any way to make them all inherit in the same way.

推荐答案

列表框以及其他一些控件不会继承前景属性的原因是,它明确地默认风格二传手覆盖。不幸的是,即使你指定自定义样式列表框不包含前景色属性setter,它仍然会回落到试图将继承其父项的值之前,使用默认的样式。

The reason the ListBox and some other controls are not inheriting the Foreground property is that it is explicitly overridden with a Setter in the default style. Unfortunately even if you assign a custom style to the ListBox that doesn't include the Foreground property setter, it will still fall back to using the default style before attempting to inherit the value of its parent.

的precedence确定属性值的顺序是:

The order of precedence for determining the property value is:

  1. 本地值
  2. 样式触发器
  3. 模板触发器
  4. 样式设置器
  5. 在主题风格的触发器
  6. 在主题风格的setter
  7. 属性值继承
  8. 默认值

由于#6在控件的默认样式定义,WPF并不试图确定#7的价值。

Since #6 is defined in the default style for the control, WPF does not attempt to determine the value of #7.

这篇关于我可以得到一个WPF列表框,以继承父元素刷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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