Q:

Animation style was overridden

I was making animation for all my TreeView.....
Having a app.xaml with:

<Style TargetType="{x:Type TreeView}">
    <Style.Resources>
        <Style TargetType="{x:Type TreeViewItem}">
            <Style.Triggers>
                <EventTrigger RoutedEvent="TreeViewItem.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                             From="0" To="1" BeginTime="00:00:00" Duration="00:00:01" FillBehavior="Stop"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>
      </Style.Resources>
</Style>

It works for for every TreeView, I can see the TreeViewItem fading in.
But then if the TreeView is defined as below with Triggers in the style:
   <TreeView>
        <TreeView.Resources>
            <Style TargetType="{x:Type TreeViewItem}">
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="True">
                          //Do some work
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TreeView.Resources>
        <TreeViewItem Header="Item1">
            <TreeViewItem Header="Item2">
                <TreeViewItem Header="Item3"/>
                <TreeViewItem Header="Item4"/>
            </TreeViewItem>
            <TreeViewItem Header="Item5"/>
        </TreeViewItem>            
        <TreeViewItem Header="Item6"/>
    </TreeView>

The animation will not be working anymore.
Is there any solution or workaround for this?  I don't really want to put the whole animation code inside the TreeView...

A:

1) create a base named style, with your existing style
<Style x:Key="baseTreeViewStyle" 
       TargetType="{x:Type TreeViewItem}"> existing style here </Style>

2) create a style without a name based on your base style - this will be your implicit global style
<Style TargetType="{x:Type TreeViewItem}" 
       BasedOn={StaticResource baseTreeViewStyle} />

3) extend the base style in your tree view
<Style TargetType="{x:Type TreeViewItem}" 
       BasedOn="{StaticResource baseTreeViewStyle}">
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="True">
              //Do some work
        </Trigger>
    </Style.Triggers>
</Style>

Now you get an implicit global style, but if you need specific additional behaviour you override the base style.
To be even more thorough your base style should be based on the default TreeViewItem style
<Style x:Key="baseTreeViewStyle" 
       TargetType="{x:Type TreeViewItem}" 
       BasedOn="{StaticResource {x:Type TreeViewItem}}"> 
           existing style here 
</Style>

