Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign resource dictionary for custom controls in a dll

I have a WPF custom control MyControl.cs in my application project (.exe) with its style in a resource dictionary in MyControlResources.xaml. This xaml is specified in app.xaml as a part of the merged dictionaries. Everything works fine.

Now I want to move this custom control into an existing DLL project that the application references. Is there a way that I can create the resource dictionary "assignment" in the DLL and make it transparent to the callers i.e. the application project can use it like any built-in control that doesn't require you to know anything about resource dictionary?

I've read about creating a new custom control project can do the trick, but it's only one control for which I don't want to create a new project for. Anyone knows how to do it in an existing class library DLL?

like image 328
NS.X. Avatar asked Nov 04 '22 13:11

NS.X.


1 Answers

This answer helped me find the trick.

  1. Create a file called Themes\Generic.xaml to merge the resource dictionary.

  2. Add the following attribute to Assembly.cs

    [assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]

like image 89
NS.X. Avatar answered Nov 22 '22 21:11

NS.X.