title: In WPF can you base one DataTemplate on another like you can with a Style?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4443600/datatemplate-inheritance">Datatemplate inheritance</a>  </p>
  </blockquote>
  
  
  
  <p>I have several data types that are not subclasses, nor do they share an interface, but they do have common properties that I want to display in a XAML DataTemplate.  That said, I know this is possible...</p>
  
  <pre><code>&lt;!-- Basic Style Inheritance --&gt;
  &lt;Style x:Key="FooStyle" TargetType="Foo" /&gt;
  &lt;Style x:Key="EnhancedFooStyle" TargetType="Foo" BasedOn="{StaticResource FooStyle}" /&gt;
  
  &lt;!-- Inheritance By Type --&gt;
  &lt;Style x:Key="BaseItemStyle"&gt;
      &lt;Setter Property="Control.Background" Value="Yellow" /&gt;
  &lt;/Style&gt;
  
  &lt;!-- These three data types share the same 'BaseItemStyle' --&gt;
  &lt;Style TargetType="ListBoxItem" BasedOn="{StaticResource BaseItemStyle}" /&gt;
  &lt;Style TargetType="ComboBoxItem" BasedOn="{StaticResource BaseItemStyle}" /&gt;
  &lt;Style TargetType="TreeViewItem" BasedOn="{StaticResource BaseItemStyle}" /&gt;
  </code></pre>
  
  <p>But can we do something similar like this for data templates which don't have the <code>BasedOn</code> property?</p>
  
  <pre><code>&lt;DataTemplate x:Key="CommonTemplate"&gt;
      &lt;!-- Common Stuff Goes Here --&gt;
  &lt;/DataTemplate&gt;
  
  &lt;!-- These three datatypes share the same DataTemplate --&gt;
  &lt;DataTemplate DataType="Foo1" BasedOn="{StaticResource CommonTemplate}" /&gt;
  &lt;DataTemplate DataType="Foo2" BasedOn="{StaticResource CommonTemplate}" /&gt;
  &lt;DataTemplate DataType="Foo3" BasedOn="{StaticResource CommonTemplate}" /&gt;
  </code></pre>
  
  <p>I know <code>BasedOn</code> isn't what we want here because it's not 'based on' but rather 'is' in this scenario, but not sure how to do that purely in XAML.  As I'm writing this, I have an idea, but I feel using <code>UserControl</code> is cheating...</p>
  
  <pre><code>&lt;UserControl x:Key="CommonTemplate" x:Shared="False"&gt;
      &lt;!-- Common Stuff Goes Here --&gt;
  &lt;/UserControl&gt;
  
  &lt;!-- These three datatypes share the same DataTemplate --&gt;
  &lt;DataTemplate DataType="Foo1" BasedOn="{StaticResource CommonTemplate}"&gt;
      &lt;StaticResource ResourceKey="CommonTemplate" /&gt;
  &lt;/DataTemplate&gt;
  
  &lt;DataTemplate DataType="Foo2" BasedOn="{StaticResource CommonTemplate}" /&gt;
      &lt;StaticResource ResourceKey="CommonTemplate" /&gt;
  &lt;/DataTemplate&gt;
  
  &lt;DataTemplate DataType="Foo3" BasedOn="{StaticResource CommonTemplate}" /&gt;
      &lt;StaticResource ResourceKey="CommonTemplate" /&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>Thanks!</p>