Loading generic.xaml from embedded assembly

My WPF application uses custom controls in a referenced library. To simplify deployment, all dependent DLLs are embedded resources of the application EXE file.
Read Jeffrey Richter: Excerpt #2 from CLR via C#, Third Edition to get the details.

The problem with this setup is that the generic.xaml from the referenced library is not applied. Resulting in an empty from on application start.

Expected

Expected

Actual

Actual

By writing some information to the tracelog I noted the ApplyTemplate was not fired. There are loads of discussions about this when you google, but all discuss the assembly: ThemeInfo settings. Which is not my problem. Everything works fine when the referenced library is located in the same folder …

Eventually I loaded the generic.xaml only in the controls and removed the MergedDictionaries from my MainWindow. This did the trick. Try my Sample solution. On the first run you get the almost empty window after the 3 second wait. Then locate the adding of generic.xaml in the constructor of MainWindow.xaml.cs and comment/remove it. Now everything works even when MyControl is removed.

About erictummers

My work as a recruited developer changes almost every month. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Development and tagged , , , , , . Bookmark the permalink.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s