title: WPF: IsMouseOver trigger not working for datatemplate
body: <p>I'm trying to get the IsMouseOver trigger working for datatemplate. For some reason it is not firing. I also tried the <a href="http://www.wpfmentor.com/2009/01/how-to-debug-triggers-using-trigger.html" rel="nofollow">http://www.wpfmentor.com/2009/01/how-to-debug-triggers-using-trigger.html</a> but I do not see anything in the trace. Here is the code:</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Window x:Class="FirstSImpleDataApp.Window4"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="Window4" Height="300" Width="300"&gt;
      &lt;Window.Resources&gt;
      &lt;ResourceDictionary&gt;
              &lt;DataTemplate x:Key="tmptemplate"&gt;
                  &lt;Border x:Name="brd" BorderBrush="Black" BorderThickness="2"&gt;
                      &lt;TextBlock x:Name="txt"&gt;my text box&lt;/TextBlock&gt;
                  &lt;/Border&gt;
                  &lt;DataTemplate.Triggers&gt;
                      &lt;Trigger Property="IsMouseOver" Value="True"&gt;
                          &lt;Setter TargetName="txt" Property="Background" Value="Red"&gt;&lt;/Setter&gt;
                          &lt;Setter TargetName="txt" Property="Foreground" Value="Green"&gt;&lt;/Setter&gt;
                          &lt;Setter TargetName="brd" Property="Background" Value="Green"&gt;&lt;/Setter&gt;
                      &lt;/Trigger&gt;
                  &lt;/DataTemplate.Triggers&gt;
              &lt;/DataTemplate&gt;
  
  
  
          &lt;/ResourceDictionary&gt;
      &lt;/Window.Resources&gt;
      &lt;Canvas x:Name="can" Loaded="can_Loaded"&gt;
  
      &lt;/Canvas&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Code behind:</p>
  
  <pre><code>   public partial class Window4 : Window
      {
          public Window4()
          {
              InitializeComponent();
          }
  
          private void can_Loaded(object sender, RoutedEventArgs e)
          {
              var tmp = this.TryFindResource("tmptemplate") as DataTemplate;
              var obj = (FrameworkElement)tmp.LoadContent();
              can.Children.Add(obj);
          }
      }
  </code></pre>
  
  <p>Any help is appreciated!</p>