3 minute read

I was thinking about the [WPF Theme Replacer] some more and there are a few things you should be aware of when designing your theme to work just like a Microsoft WPF theme.

  1. Remember that you’re replacing the theme dictionary and need to provide a theme for all the controls unless you want the generic/classic theme to be invoked, assuming there is one.  For 3rd party controls, they probably offer coverage for at least one of the themes so you could just copy and start with it for those controls. - Aero Theme
  1. DynamicResource references that don’t resolve to a component key, do not work if the resource is located inside the theme dictionary.  This isn’t the fault of the WPF Theme Replacer, that’s just the way real theme dictionaries work.  I think it’s a “Works by Design” bug in WPF, seeing as how the Theme dictionary is supposed to be checked when dynamic resources resolve, so you’d think it would locate them in its own dictionary.  But there are workarounds,
  • DynamicResource still works if the resource needed is located in the Application resource dictionary.  So first setting your theme with the WPF Theme Replacer, with a ton of DynamicResource references to Colors and Brushes. Then when users want to switch between the Dark, Light, and Cornflower Blue versions of your theme, it’s just a matter of swapping out the color palette dictionary you’ve merged into the Application resource dictionary.  So doing things like that with the WPF Theme Replacer is still very much viable.

For my own projects I would add some code-behind to my resource dictionary for my theme containing an expanded color palette that my theme uses and have all the brushes/colors as static property component keys just like they do for the system colors and people can map to those.  Same thing as before…just better defined than some random key name.

  1. The default Aero WPF Theme mentioned in #1 actually contains bugs.  :(  If you compare the “sample” Aero theme to the actual Aero theme in WPF you’ll notice some differences.  Such as the dropdown arrow on the expander.  In the version Microsoft distributed they attempt to lookup several brushes using DynamicResource. You’ll get a handful of data binding errors if you use the one I linked above in the WPF Theme Replacer.  They’re easy enough to fix, just remove the brushes and their references.  Alternatively you can just ask Blend for a copy of the style for the expander.  I think the one for Aero is returned on any system.