title: Extending the style of a custom control in xaml
body: <p>I am developing a WPF application, and have created a custom control, we will call it 'CControl'. In the xaml document where I am designing the layout of my application. I import the style with:</p>
  
  <pre><code>xmlns:my="clr-namespace:My.Controls"
  </code></pre>
  
  <p>and am able to use the control just fine. The problem is I want to extend the style on CControl. In the Resource Dictionary, I am able to set: </p>
  
  <pre><code>        &lt;Style TargetType="{x:Type my:CControl}"&gt;
              &lt;Setter Property="Margin" Value="5 0 5 3" /&gt;
          &lt;/Style&gt;
  </code></pre>
  
  <p>This applies the style to the Control, but doesn't import the style defined by CControl, so I use:</p>
  
  <pre><code>        &lt;Style TargetType="{x:Type my:CControl}" BasedOn="{StaticResource {x:Type my:CControl}}"&gt;
              &lt;Setter Property="Margin" Value="5 0 5 3" /&gt;
          &lt;/Style&gt;
  </code></pre>
  
  <p>The problem is when my framework tries to load the xaml I get the following exception:</p>
  
  <pre><code>System.Windows.Markup.XamlParseException occurred
    Message='Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '18' and line position '54'.
  Source=PresentationFramework
  LineNumber=18
  LinePosition=54
  StackTrace:
     at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
     at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
     at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, Boolean skipJournaledProperties, Uri baseUri)
     at System.Windows.Markup.XamlReader.Load(XamlReader xamlReader, ParserContext parserContext)
     at System.Windows.Markup.XamlReader.Load(XamlReader reader)
     at FATPOT.Whiteboard.Report.Show() in C:\...\Report.cs
  InnerException: 
     Message=Cannot find resource named 'My.Controls.CControl'. Resource names are case sensitive.
     Source=PresentationFramework
     StackTrace:
          at System.Windows.StaticResourceExtension.ProvideValueInternal(IServiceProvider serviceProvider, Boolean allowDeferredReference)
          at System.Windows.StaticResourceExtension.ProvideValue(IServiceProvider serviceProvider)
          at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider)
     InnerException: 
  </code></pre>
  
  <p>I have tried different ways of using BasedOn and havent gotten anything to work. Any help would be extremely useful. </p>
  
  <p>Thanks</p>
  
  <p>Josh</p>