Prefered Style Container for the Components in the DataTemplate The following XAML is a close (tidied up) version of what I have use in my WPF application. If you have noticed there are two Styles applied to the same component (Border in this example.)

I would like to know how can I merge the 2nd Style into 1st to make it apply to all the Borders included in the DataTemplate.



&lt;DataTemplate DataType="{x:Type m:myFoo}"&gt;
  &lt;DataTemplate.Resources&gt;
    &lt;!-- 1) Style Applied to the Border --&gt;
    &lt;Style TargetType="Border"&gt;
      &lt;Setter Property="Margin" Value="1"/&gt;
    &lt;/Style&gt;
  &lt;/DataTemplate.Resources&gt;
  &lt;Border&gt;
    &lt;Grid&gt;
      &lt;Border&gt;
        &lt;!-- Guts --&gt;
      &lt;Border&gt;
    &lt;/Grid&gt;
    &lt;Border.Style&gt;
      &lt;!-- 2) Style Applied to the Border --&gt;
      &lt;Style TargetType="Border"&gt;
        &lt;Style.Triggers&gt;
          &lt;DataTrigger Binding="{Binding Path=Active}"&gt;
            &lt;Setter Property="Background" Value="OrangeRed"/&gt;
          &lt;/DataTrigger&gt;
        &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
    &lt;/Border.Style&gt;
  &lt;/Border&gt;
&lt;/DataTemplate&gt;


I am familiar with the fact that 2nd Style will only apply to its own component unlike the 1st which will be applied to any Border included in the DataTemplate.
You can merge the two style in the DataTemplate.Resources so that it can be applied in all the Borders inside the DataTemplate. Refer the below code.

&lt;DataTemplate DataType="{x:Type m:myFoo}"&gt;
        &lt;DataTemplate.Resources&gt;
            &lt;!-- 1) Style Applied to the Border --&gt;
            &lt;Style TargetType="Border"&gt;
                &lt;Setter Property="Margin" Value="1"/&gt;
                &lt;Style.Triggers&gt;
                    &lt;DataTrigger Binding="{Binding Path=Active}"&gt;
                        &lt;Setter Property="Background" Value="OrangeRed"/&gt;
                    &lt;/DataTrigger&gt;
                &lt;/Style.Triggers&gt;
            &lt;/Style&gt;
        &lt;/DataTemplate.Resources&gt;
        &lt;Border&gt;
            &lt;Grid&gt;
                &lt;Border&gt;
                    &lt;!-- Guts --&gt;
                 &lt;/Border&gt;
            &lt;/Grid&gt;                
        &lt;/Border&gt;
    &lt;/DataTemplate&gt;