3

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?

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Michaud
  • 1,098
  • 8
  • 12

4 Answers4

1

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();
}
Michaud
  • 1,098
  • 8
  • 12
0

For future reference, my XAML file was found in a subdirectory of the solution which needed the / character but also file was further in a subdirectory named Assets within it.

<ResourceDictionary 
     Source="/MyAssemblyName;component/Assets/RadResources.xaml" />

Also the .XAML file was built as Page in the solution.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
0

This question may be of help, although, honestly, I'm still trying to figure it out myself: Using MEF to import a WPF DataTemplate?

Community
  • 1
  • 1
Andrew Garrison
  • 6,977
  • 11
  • 50
  • 77
0

//load other.dll dynamically first,and then use the following code:

       StreamResourceInfo srf = Application.GetResourceStream(new Uri("otherdll;component/Resources/Brush.xaml", UriKind.Relative));

        StreamReader sr = new StreamReader(srf.Stream);
        string stt = sr.ReadToEnd();
        ResourceDictionary dict = XamlReader.Load(stt) as ResourceDictionary;
        Application.Current.Resources.MergedDictionaries.Add(dict);