日期:2014-05-17  浏览次数:20691 次

WPF,属性继承问题

<Window x:Class="Using_Inherited_Dps.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStartupLocation="CenterScreen" 
Title="依赖项属性的继承" Height="400" Width="578" Foreground="Red">
    <StackPanel >
        <Label Content="熊俊" />
    </StackPanel>
</Window>


上面的Lable的字体没有继承Window的Red,不是红色,为什么呢?

------解决方案--------------------
初学WPF的路过。。
------解决方案--------------------
你看下Lable的模版就晓得了
------解决方案--------------------

<Style x:Key="LabelStyle1"
        TargetType="{x:Type Label}">
    <Setter Property="Foreground"
            Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
    <Setter Property="Background"
            Value="Transparent" />
    <Setter Property="Padding"
            Value="5" />
    <Setter Property="HorizontalContentAlignment"
            Value="Left" />
    <Setter Property="VerticalContentAlignment"
            Value="Top" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Label}">
                <Border BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"