title: WPF ControlTemplate: Using StaticResource leads to XML Parse Exception during Runtime. Why?
body: <p>I've got the following simple ControlTemplate for a Tooltip in a ResourceDictionary:</p>
  
  <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:s="clr-namespace:System;assembly=mscorlib"
                  xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
                  xmlns:local="clr-namespace:SIMOCRANECMSReporting.Resources.ControlTemplates"&gt;
  &lt;ControlTemplate x:Key="CTToolTipRoundCorners" TargetType="{x:Type ToolTip}"&gt;
      &lt;mwt:SystemDropShadowChrome Color="Gray" CornerRadius="3" Name="Shdw" SnapsToDevicePixels="True"&gt;
          &lt;Border Background="#FFF6F2F2" Opacity="1" CornerRadius="3" BorderThickness="1" BorderBrush="#FFD5D1D1"&gt;
              &lt;Grid&gt;
                  &lt;ContentPresenter Margin="{TemplateBinding Padding}" DataContext="{TemplateBinding DataContext}" /&gt;
              &lt;/Grid&gt;
          &lt;/Border&gt;
      &lt;/mwt:SystemDropShadowChrome&gt;
      &lt;ControlTemplate.Triggers&gt;
          &lt;Trigger Property="ToolTipService.HasDropShadow"&gt;
              &lt;Setter Property="mwt:SystemDropShadowChrome.Effect" TargetName="Shdw"&gt;
                  &lt;Setter.Value&gt;
                      &lt;DropShadowEffect ShadowDepth="5" Opacity="0.8"/&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
              &lt;Setter Property="FrameworkElement.Margin" TargetName="Shdw"&gt;
                  &lt;Setter.Value&gt;
                      &lt;Thickness&gt;0,0,10,10&lt;/Thickness&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
              &lt;Setter Property="mwt:SystemDropShadowChrome.Color" TargetName="Shdw"&gt;
                  &lt;Setter.Value&gt;
                      &lt;Color&gt;#00878787&lt;/Color&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
              &lt;Trigger.Value&gt;
                  &lt;s:Boolean&gt;True&lt;/s:Boolean&gt;
              &lt;/Trigger.Value&gt;
          &lt;/Trigger&gt;
      &lt;/ControlTemplate.Triggers&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p></p>
  
  <p>It is merged with the other resources in App.xaml...</p>
  
  <pre><code>&lt;Application x:Class="SIMOCRANECMSReporting.App"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           StartupUri="MainWindow.xaml"&gt;
  &lt;Application.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;ResourceDictionary.MergedDictionaries&gt;
              &lt;ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" /&gt;
              &lt;ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/&gt;
              &lt;ResourceDictionary Source="/Resources/RedTextBox.xaml"/&gt;
              &lt;ResourceDictionary Source="/Resources/RedTextBox2.xaml"/&gt;
              &lt;ResourceDictionary Source="/Resources/ControlTemplates/CTToolTipRoundCorners.xaml"/&gt;
          &lt;/ResourceDictionary.MergedDictionaries&gt;
      &lt;/ResourceDictionary&gt;
  
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p></p>
  
  <p>... and used in a style.trigger section of a TextBox style:</p>
  
  <pre><code>&lt;Style x:Key="RedTextBox2" TargetType="{x:Type TextBoxBase}" BasedOn="{x:Null}"&gt;
      ... some more xaml ...
      &lt;Style.Triggers&gt;
          &lt;Trigger Property="Validation.HasError" Value="True"&gt;
              &lt;Setter Property="ToolTip"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ToolTip Template="{StaticResource ResourceKey=CTToolTipRoundCorners}" 
                               DataContext="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget}" 
                               Padding="10" HasDropShadow="True"&gt;
                          &lt;ItemsControl ItemsSource="{Binding Path=(Validation.Errors)}" DisplayMemberPath="ErrorContent"/&gt;
                      &lt;/ToolTip&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Trigger&gt;
      &lt;/Style.Triggers&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>Using StaticResource to reference the template leads to an exception:</p>
  
  <pre><code>&lt;ToolTip Template="{StaticResource ResourceKey=CTToolTipRoundCorners}" ... /&gt;
  </code></pre>
  
  <p>... while using DynamicResource works perfectly:</p>
  
  <pre><code>&lt;ToolTip Template="{DynamicResource ResourceKey=CTToolTipRoundCorners}" ... /&gt; 
  </code></pre>
  
  <p><strong>Question: Can anybody explain why StaticResource doesn't work?</strong></p>