title: XamlParseException occurred: Failed to create a 'System.Windows.Style' from the text 'PhoneMasterGridColumnHeader'
body: <p>I have four datagrids on a Silverlight 4 page.  I'm trying to set different column header styles for each grid.  I found this XAML which works when I embed it in each DataGrid inside <code>&lt;sdk:DataGrid.ColumnHeaderStyle&gt;</code> tags:</p>
  
  <pre><code>  &lt;Style TargetType="primitives:DataGridColumnHeader" &gt;
      &lt;Setter Property="Template"&gt;
        &lt;Setter.Value&gt;
          &lt;ControlTemplate TargetType="primitives:DataGridColumnHeader"&gt;
            &lt;Grid Name="Root"&gt;
              &lt;vsm:VisualStateManager.VisualStateGroups&gt;
                &lt;vsm:VisualStateGroup x:Name="SortStates" &gt;
                  &lt;vsm:VisualStateGroup.Transitions&gt;
                    &lt;vsm:VisualTransition GeneratedDuration="00:00:0.1" /&gt;
                  &lt;/vsm:VisualStateGroup.Transitions&gt;
                  &lt;vsm:VisualState x:Name="Unsorted" /&gt;
                  &lt;vsm:VisualState x:Name="SortAscending"&gt;
                    &lt;Storyboard&gt;
                      &lt;DoubleAnimation Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0" /&gt;
                    &lt;/Storyboard&gt;
                  &lt;/vsm:VisualState&gt;
                  &lt;vsm:VisualState x:Name="SortDescending"&gt;
                    &lt;Storyboard&gt;
                      &lt;DoubleAnimation Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0" /&gt;
                      &lt;DoubleAnimation Storyboard.TargetName="SortIconTransform" Storyboard.TargetProperty="ScaleY" Duration="0" To="-.9" /&gt;
                    &lt;/Storyboard&gt;
                  &lt;/vsm:VisualState&gt;
                &lt;/vsm:VisualStateGroup&gt;
              &lt;/vsm:VisualStateManager.VisualStateGroups&gt;
              &lt;Grid.RowDefinitions&gt;
                &lt;RowDefinition Height="*" /&gt;
                &lt;RowDefinition Height="*" /&gt;
                &lt;RowDefinition Height="Auto" /&gt;
              &lt;/Grid.RowDefinitions&gt;
              &lt;Grid.ColumnDefinitions&gt;
                &lt;ColumnDefinition Width="Auto" /&gt;
                &lt;ColumnDefinition Width="*" /&gt;
                &lt;ColumnDefinition Width="Auto" /&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;Rectangle x:Name="BackgroundRectangle" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2"&gt;
                &lt;Rectangle.Fill&gt;
                  &lt;LinearGradientBrush StartPoint="0,0" EndPoint="0,1"&gt;
                    &lt;GradientStop Color="Transparent" Offset="0" /&gt;
                    &lt;GradientStop Color="LavenderBlush" Offset="1" /&gt;
                  &lt;/LinearGradientBrush&gt;
                &lt;/Rectangle.Fill&gt;
              &lt;/Rectangle&gt;
              &lt;ContentPresenter Grid.RowSpan="2" Content="{TemplateBinding Content}" Cursor="{TemplateBinding Cursor}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" /&gt;
              &lt;Rectangle Name="VerticalSeparator" Grid.RowSpan="2" Grid.Column="2" Width="1" VerticalAlignment="Stretch" Fill="{TemplateBinding SeparatorBrush}" Visibility="{TemplateBinding SeparatorVisibility}" /&gt;
              &lt;Path Grid.RowSpan="2" Name="SortIcon" RenderTransformOrigin=".5,.5" HorizontalAlignment="Left" VerticalAlignment="Center" Opacity="0" Grid.Column="1" Stretch="Uniform" Width="8" Data="F1 M -5.215,6.099L 5.215,6.099L 0,0L -5.215,6.099 Z "&gt;
                &lt;Path.Fill&gt;
                  &lt;SolidColorBrush Color="#FF444444" /&gt;
                &lt;/Path.Fill&gt;
                &lt;Path.RenderTransform&gt;
                  &lt;TransformGroup&gt;
                    &lt;ScaleTransform x:Name="SortIconTransform" ScaleX=".9" ScaleY=".9"  /&gt;
                  &lt;/TransformGroup&gt;
                &lt;/Path.RenderTransform&gt;
              &lt;/Path&gt;
            &lt;/Grid&gt;
          &lt;/ControlTemplate&gt;
        &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
    &lt;/Style&gt;
  </code></pre>
  
  <p>When I put it in a separate resource dictionary and remove the aforementioned tags, it also works, applying to all four headers.  But when I try to create a specific version of it in the resource dictionary but changing the first line to this:</p>
  
  <pre><code>&lt;Style x:Key="ADGridColumnHeader" TargetType="primitives:DataGridColumnHeader" &gt;
  </code></pre>
  
  <p>and adding this to the DataGrid:</p>
  
  <pre><code>ColumnHeaderStyle="PhoneMasterGridColumnHeader"
  </code></pre>
  
  <p>I get the error: XamlParseException occurred: Failed to create a 'System.Windows.Style' from the text 'PhoneMasterGridColumnHeader'.  I can't work out what's wrong.  I'm still struggling to get to grips with Styles and Resource Dictionaries.  Any idea?</p>