WPF里的Foreground能传给子控件吗
梁苏彬 2008-12-04 10:16:23 我想要在顶层窗口设置Foreground属性,希望里面的控件都用这个属性,能不能做到?经过我测试并不是不可以,但是属性不能很好的传递。如下面的窗口,两个TextBlock的字体颜色变成红色了,但CheckBox的颜色没变。在窗口里使用了TabControl后情况更奇怪,有时有效有时无效,有时在设计窗口能看到颜色,但一编译又没了。我用的是vs2008没有打补丁。
<Window x:Class="sandbox.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" Foreground="Red">
<Grid>
<StackPanel>
<TextBlock>TextBlock1</TextBlock>
<TextBlock>TextBlock3</TextBlock>
<CheckBox>CheckBox1</CheckBox>
</StackPanel>
</Grid>
</Window>