Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get at ResourceDictionary style when it is loaded from external xap and assemblies are MEF-fed?

I've got the following setup:

The main application loads a XAP with an IPlugin implementation. The Plugin contains a 'DisplayPanel' that contains a referenced Control with other controls. The DisplayPanel here is simply a container control to show referenced Control.

This referenced Control, from an assembly, uses a Style from a ResourceDictionary xaml in this assembly. At least that's what I want to have. The problem is that the referenced Control throws an error:

Cannot find a Resource with the Name/Key PlayerPanelGrad [Line: 1500 Position: 127]

I've tried to get at the style by referencing theResourceDictionary through a Merged Resource dictionary reference:

       <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="TableControls;component/ControlsStyle.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

But that doesn't work.

How would you approch this?

like image 901
Michaud Avatar asked Dec 07 '25 10:12

Michaud


1 Answers

the only way i got it to work is by loading the Resource dictionary into the control (in a Class Library) programmatically before the InitializeComponent call:

public ActionPanel()
{
     StreamResourceInfo sr = Application.GetResourceStream(
          new Uri("TableControls;component/ControlsStyle.xaml", UriKind.Relative));
     Application.Current.Resources.Add("plop",sr.Stream);
     // Required to initialize variables
     InitializeComponent();
}
like image 136
Michaud Avatar answered Dec 10 '25 01:12

Michaud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!