我有窗口,在這裏我設置一些屬性財產繼承通過的TabControl
<Window Foreground="White" ...
現在我所有的孩子獲得該財產繼承的,對不對?像這樣
<Window>
<Grid>
<Label> <-- has Foreground="White" without need to explicitly specify it -->
...
但是,一旦我使用TabControl
,繼承就會中斷。
<Window>
<Grid>
<TabControl>
<TabItem>
<Grid>
<Label> <-- doesn't inherit Foreground property from Window -->
我不能設置爲Foreground
TabControl
,也許這就是原因。問題是爲什麼以及要做什麼?我可以使用樣式,但是有沒有其他的,更明顯和更少code-ish的方式?
控件不僅繼承屬性DataContext和樣式。你可以用[Snoop](http://snoopwpf.codeplex.com/)來查看它(在你的例子中'Label'的前景實際上是黑色的) –
我的意思是['property property inheritance'](http:// msdn.microsoft.com/en-us/library/ms753197.aspx)。真的很討厭自己先說錯了。 – Sinatr
@TzahMama,這是不正確的。當然,某些控件(如容器控件和基於文本的控件)會繼承屬性值。「DependencyProperty」屬性值繼承將是非常沒有意義的,否則,不是嗎? – Sheridan