0

I have faced a problem with the WPF styles.

In the root userControl I am having the resource defined like this:

<UserControl.Resources>
    <Style TargetType="{x:Type MyControl}">
        <Setter Property="MyControl.AAA" Value="Value1" />
    </Style>
</UserControl.Resources>

This works just fine, it affects all the MyControl elements in the whole visual tree hierarchy.

If I attempt to change the setter using the DataTrigger, like this:

<UserControl.Resources>
    <Style TargetType="{x:Type MyControl}">
        <Style.Triggers>                
           <DataTrigger Binding="{Binding Path=SelectedAAAValue}" Value="Value1">
               <Setter Property="MyControl.AAA" Value="Value1" />
           </DataTrigger>
           <DataTrigger Binding="{Binding Path=SelectedAAAValue}" Value="Value2">
               <Setter Property="MyControl.AAA" Value="Value2"/>
           </DataTrigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>

The style is applied only to the root element of a specific MyControl type.

Can anybody explain me why it is happening and how can I apply the style to all specific elements via DataTriggers?

Many thanks for any help. Ondra

4

1 回答 1

0

我不知道为什么会这样,但也许你可以在这里找到更多信息。这当然只是在您设置 MyControl.AAA 的属性是 DependecyProperty 的情况下。

下一段,在图像下,应该解释更多。

于 2013-01-22T22:21:17.027 回答