I have a WPF app that I am trying to convert to a DLL. The problem is that I have a number of application level resources set up in my App.XAML. In the dll I am trying to set my resources programatically.
To load my resources programatically I have this:
ResourceDictionary myResourceDictionary = new ResourceDictionary();
myResourceDictionary.Source = new Uri("C:\\Users\\Ash\\Documents\\Visual Studio 2010\\Projects\\moo Process Flow Manager\\moo Process Flow Manager\\Resources\\Styles\\Shared.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary = new ResourceDictionary();
myResourceDictionary.Source = new Uri("C:\\Users\\Ash\\Documents\\Visual Studio 2010\\Projects\\moo Process Flow Manager\\moo Process Flow Manager\\Resources\\Styles\\ToolBar.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary = new ResourceDictionary();
myResourceDictionary.Source = new Uri("C:\\Users\\Ash\\Documents\\Visual Studio 2010\\Projects\\moo Process Flow Manager\\moo Process Flow Manager\\Resources\\Styles\\ZoomBox.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
This line:
myResourceDictionary.Source = new Uri("C:\\Users\\Ash\\Documents\\Visual Studio 2010\\Projects\\moo Process Flow Manager\\moo Process Flow Manager\\Resources\\Styles\\ZoomBox.xaml");
Throws the following error at runtime:
'Failed to create a 'Type' from the text 's:ZoomBox'.' Line number '5' and line position '12'.
With the inner exception:
{"Type reference cannot find type named '{clr-namespace:Arkitec.moo.ProcessFlowManager.Controls}ZoomBox'."}
Here is the line thats causing the error within zoombox.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:Arkitec.moo.ProcessFlowManager.Controls">
<Style TargetType="{x:Type s:ZoomBox}">
Here is where the class is declared that it should be looking at in zoombox.cs:
namespace Arkitec.moo.ProcessFlowManager.Controls
{
public class ZoomBox : Control
{
Please let me know if you need anymore information.
EDIT: As per Guilammes answert I tried:
myResourceDictionary.Source = new Uri("Resources/Styles/Shared.xaml", UriKind.Relative);
But get the following error:
Cannot locate resource 'resources/styles/shared.xaml'.