views:

14

answers:

1

I have a Custom Controls Library (ex. MyCustomControls.dll) that is a plugin to a 3rd party application. It outputs as a class library and is invoked by the 3rd party application at runtime. My issue is the custom styles I have defined for various user controls like listviewitem, textblock now cannot be loaded at the application level.

How can I add my custom styles to the resource lookup hierarchy such that all the controls in the library will use my custom styles?

Example, if I define the style below, all the controls in MyCustomControls.dll will not see it when they are created. But if I add MyCustomControls.dll to an application and load it in the application resources, the style gets applied.

Note: 3rd party application is not a WPF application. Application.Current returns null at runtime.

A: 

If you don't have access to the 3rd party app, and if it is not a WPF application (is it Silverlight?) you cannot inject your styles written in xaml for WPF. Also, only the 3rd party application will know how to apply skins later on. I guess, if it's not your app, the only thing you can do is follow the "instructions of the manufacturer".

Just for reference: If you own both sides - the main app and the resources to be plugged in, you could use MergeDictionaries to merge the resources dll in. In order to access the resource's dll you need to use the Pack URI syntax. Something like this:

In App.xaml:

   <ResourceDictionary>
       <ResourceDictionary.MergedDictionaries>
          <ResourceDictionary Source="pack://application:,,,/YOUR_DLL;component/SUBFOLDER/YOURCUSTOMSTYLES.xaml"/>
       </ResourceDictionary.MergedDictionaries>
   </ResourceDictionary>

In these scenarios it is important to keep the key of your resources identical to the ones the main application is expecting. This is because the typical skinning mechanism is to use DynamicResource when consuming the resources, and therefore, they are looked-up by the "key" every time they are used. If you replace an existing resource with another one using the same key, for example, switch a resource called "ButtonBackground" to Yellow, and the application uses this resource DYNAMICALLY throughout the application as the background of the buttons, all the buttons should become yellow.

Gustavo Cavalcanti
Thanks for reply. The 3rd party application is not a WPF application and I don't have any control over it. Edited question to reflect this.
I've updated my answer. Unfortunately there's nothing you can do to find out how to inject resources in a 3rd party app, especially a non-WPF and non-Silverlight app...
Gustavo Cavalcanti