Q:

WPF ControlTemplate: Using StaticResource leads to XML Parse Exception during Runtime. Why?

I've got the following simple ControlTemplate for a Tooltip in a ResourceDictionary:
<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">
<ControlTemplate x:Key="CTToolTipRoundCorners" TargetType="{x:Type ToolTip}">
    <mwt:SystemDropShadowChrome Color="Gray" CornerRadius="3" Name="Shdw" SnapsToDevicePixels="True">
        <Border Background="#FFF6F2F2" Opacity="1" CornerRadius="3" BorderThickness="1" BorderBrush="#FFD5D1D1">
            <Grid>
                <ContentPresenter Margin="{TemplateBinding Padding}" DataContext="{TemplateBinding DataContext}" />
            </Grid>
        </Border>
    </mwt:SystemDropShadowChrome>
    <ControlTemplate.Triggers>
        <Trigger Property="ToolTipService.HasDropShadow">
            <Setter Property="mwt:SystemDropShadowChrome.Effect" TargetName="Shdw">
                <Setter.Value>
                    <DropShadowEffect ShadowDepth="5" Opacity="0.8"/>
                </Setter.Value>
            </Setter>
            <Setter Property="FrameworkElement.Margin" TargetName="Shdw">
                <Setter.Value>
                    <Thickness>0,0,10,10</Thickness>
                </Setter.Value>
            </Setter>
            <Setter Property="mwt:SystemDropShadowChrome.Color" TargetName="Shdw">
                <Setter.Value>
                    <Color>#00878787</Color>
                </Setter.Value>
            </Setter>
            <Trigger.Value>
                <s:Boolean>True</s:Boolean>
            </Trigger.Value>
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

It is merged with the other resources in App.xaml...
<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">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
            <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/>
            <ResourceDictionary Source="/Resources/RedTextBox.xaml"/>
            <ResourceDictionary Source="/Resources/RedTextBox2.xaml"/>
            <ResourceDictionary Source="/Resources/ControlTemplates/CTToolTipRoundCorners.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

</Application.Resources>

... and used in a style.trigger section of a TextBox style:
<Style x:Key="RedTextBox2" TargetType="{x:Type TextBoxBase}" BasedOn="{x:Null}">
    ... some more xaml ...
    <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="True">
            <Setter Property="ToolTip">
                <Setter.Value>
                    <ToolTip Template="{StaticResource ResourceKey=CTToolTipRoundCorners}" 
                             DataContext="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget}" 
                             Padding="10" HasDropShadow="True">
                        <ItemsControl ItemsSource="{Binding Path=(Validation.Errors)}" DisplayMemberPath="ErrorContent"/>
                    </ToolTip>
                </Setter.Value>
            </Setter>
        </Trigger>
    </Style.Triggers>
</Style>

Using StaticResource to reference the template leads to an exception:
<ToolTip Template="{StaticResource ResourceKey=CTToolTipRoundCorners}" ... />

... while using DynamicResource works perfectly:
<ToolTip Template="{DynamicResource ResourceKey=CTToolTipRoundCorners}" ... /> 

Question: Can anybody explain why StaticResource doesn't work?

A:

The include order of resource dictionaries is important. Make sure the dictionary containing CTToolTipRoundCorners is included before the dictionary containing RedTextBox2
Looking at your App.xaml, i assume you should write the following:
<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">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
            <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/>
            <ResourceDictionary Source="/Resources/ControlTemplates/CTToolTipRoundCorners.xaml"/>
            <ResourceDictionary Source="/Resources/RedTextBox.xaml"/>
            <ResourceDictionary Source="/Resources/RedTextBox2.xaml"/>                
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

</Application.Resources>

