title: Problem Trying to Consolidate Styles in WPF App
body: <p>I apparently don't understand how styles are defined and used in WPF. If I include the following style in, say, the resources for a Grid containing TextBlocks:</p>
  <pre><code>&lt;Style TargetType=&quot;{x:Type TextBlock}&quot;&gt;
      &lt;Setter Property=&quot;VerticalAlignment&quot; Value=&quot;Center&quot;/&gt;
      &lt;Setter Property=&quot;Margin&quot; Value=&quot;5&quot;/&gt;
      &lt;Setter Property=&quot;HorizontalAlignment&quot; Value=&quot;Left&quot;/&gt;
  &lt;/Style&gt;
  </code></pre>
  <p>it makes all the TextBlocks have the desired attributes.</p>
  <p>But if I put it in App.xaml so that I can use the default application wide, say like this (note that I'm using MergedDictionaries because I have to include a bunch of other MahApps resource dictionaries, not shown here):</p>
  <pre><code>&lt;Application.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;ResourceDictionary.MergedDictionaries&gt;
              &lt;ResourceDictionary&gt;
                  &lt;Style TargetType=&quot;{x:Type TextBlock}&quot;&gt;
                      &lt;Setter Property=&quot;VerticalAlignment&quot; Value=&quot;Center&quot;/&gt;
                      &lt;Setter Property=&quot;Margin&quot; Value=&quot;5&quot;/&gt;
                      &lt;Setter Property=&quot;HorizontalAlignment&quot; Value=&quot;Left&quot;/&gt;
                  &lt;/Style&gt;
              &lt;/ResourceDictionary&gt;
          &lt;/ResourceDictionary.MergedDictionaries&gt;
      &lt;/ResourceDictionary&gt;
  &lt;/Application.Resources&gt;
  </code></pre>
  <p>it still defines the default for how TextBlocks are displayed at design time (in the designer)...but the app crashes upon launch with the error message:</p>
  <pre><code>System.Windows.Markup.XamlParseException
    HResult=0x80131501
    Message='Set property 'System.Windows.Style.BasedOn' threw an exception.' Line number '72' and line position '18'.
    Source=PresentationFramework
    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.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
     at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
     at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
     at J4JSoftware.RetirementModeling.MainWindow.InitializeComponent() in C:\Programming\RetirementModeling\RetirementWPF\ui\windows\MainWindow.xaml:line 1
  
    This exception was originally thrown at this call stack:
      [External Code]
  
  Inner Exception 1:
  InvalidCastException: Unable to cast object of type 'System.Double' to type 'System.Windows.Style'.
  </code></pre>
  <p>which makes no sense to me.</p>