Home > Posts > What to do if Generic.xaml doesn’t get loaded for WPF control

What to do if Generic.xaml doesn’t get loaded for WPF control

Just came across http://wangmo.wordpress.com/2007/09/27/themesgenericxaml/ which gave me a hint on why a WPF control wasn’t getting instantiated correctly when loaded from an external assembly (dll):

to load generic.xaml for WPF, at the start of Properties\AssemblyInfo.cs you need (note this isn’t used/needed in Silverlight):

using System.Windows;

and at the end of Properties\AssemblyInfo.cs you need:

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)

Mind you that if the project doesn’t show a Properties node in Solution Explorer, you have to either make a new project using the correct template (for a WPF custom control), or right click the project, select Properties, then press the Assembly Information button and enter some dummy values, then OK to create the Properties node (which also creates to a Properties subfolder and AssemblyInfo.cs file).

You can expand (drop-down) the special Properties node in solution explorer then to open AssemblyInfo.cs and add the above stuff if missing.

  1. Dinu
    2013/11/14 at 10:40

    really helpful thanks a lot….

  2. David
    2014/03/28 at 10:26

    you just made my day. Thanks, mate!

  3. 2014/08/19 at 15:03

    Thanks you soooo much. I was searching for this solution for a long time.

  4. 2014/09/04 at 17:18

    I also just noticed that if you have a key at the XAML definition of the resource used for the Style of the control, it won’t load, you should just use a Target attribute – that probably creates some implicit key internally

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: