0
votes

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

1

1 Answers

0
votes

I am not sure why that happens, but maybe you can find some more info here. This is of course only in the case that the property you are setting MyControl.AAA is a DependecyProperty.

The next paragraph, under the images, should explain more.