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

Working in a DevOps team is the best thing that happened to me. 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 )

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.