When working with WPF resources, remember to declare the resources in the correct order.
A style or template that is referenced elsewhere must be defined before it can be used. In other words, if Style1 uses BrushA as a StaticResource, then BrushA must be defined before Style1. Otherwise, you’ll get fun errors like:
Unable to cast object of type ‘MS.Internal.NamedObject’ to type ‘System.Windows.FrameworkTemplate’
It may be common knowledge, but it can be a real pain to diagnose. This is especially true if you have a large set of template and styles for an application. It gets even more fun when you have multiple themes.