title: Is it valid to use a Blend d:Style.DataContext inside WPF resource dictionary?
body: <p>When defining WPF styles, I often use the Expression Blend <code>&lt;d:Style.DataContext&gt;</code> tag to let Intellisense know what the runtime DataContext will be.  It works great.  Unfortunately I cannot seem to make this work in a resource dictionary and I am unclear as to why.</p>
  
  <p>For example, here in a style for a <code>RadTabItem</code>, I tell Intellisense that <code>SettingsPageVm</code> will be the DataContext:</p>
  
  <pre><code>&lt;UserControl x:Class="Views.ConfigureView"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
               xmlns:tk="http://schemas.telerik.com/2008/xaml/presentation"
               xmlns:viewModels="clr-namespace:ViewModels"
               d:DataContext="{d:DesignInstance viewModels:ConfigureVm}"&gt;
  
      &lt;Grid&gt;
          &lt;tk:RadTabControl ItemsSource="{Binding Categories}" &gt;  
  
              &lt;tk:RadTabControl.Resources&gt;
  
                  &lt;!-- Tell setters that SettingsPageVm will be the datacontext --&gt;
                  &lt;Style TargetType="{x:Type tk:RadTabItem}"&gt;
                      &lt;d:Style.DataContext&gt;
                          &lt;x:Type Type="viewModels:SettingsPageVm" /&gt;
                      &lt;/d:Style.DataContext&gt;
  
                  &lt;!-- (Imagine many setters here, binding to SettingsPageVm) --&gt;
  </code></pre>
  
  <p>This works fine.</p>
  
  <p>But if try I move that same style to a separate ResourceDictionary Visual Studio complains.  The editor puts a blue squiggly underneath the <code>d:Style.DataContext</code> declaration and highlights it red.  The compiler complains about it as follows:</p>
  
  <blockquote>
    <p>1>I:\Dev\MyApp\Resources\Styles\DialogStyles.xaml(13,14): error
    MC4004: Style cannot contain child 'TypeExtension'. Style child must
    be a Setter because it is added to the Setters collection. Line 13
    Position 14.</p>
  </blockquote>
  
  <p>Why is this valid in one context and not valid in another?</p>
  
  <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                      xmlns:viewModels="clr-namespace:ViewModels"
                      xmlns:tk="http://schemas.telerik.com/2008/xaml/presentation"
                      &gt;
      &lt;Style x:Key="SettingsPageTabStyle"  TargetType="{x:Type tk:RadTabItem}"&gt;
          &lt;d:Style.DataContext&gt;                           &lt;!-- *** ERROR *** --&gt;
              &lt;x:Type Type="viewModels:SettingsPageVm" /&gt;
          &lt;/d:Style.DataContext&gt;
      &lt;/Style&gt;
  &lt;/ResourceDictionary&gt;
  </code></pre>