2012-03-19 77 views
2

我有一个WPF应用程序,我试图将其转换为DLL。问题是我的App.XAML中有很多应用程序级别的资源。在DLL中,我试图以编程方式设置我的资源。命名空间混淆

要加载我的资源编程我有这样的:

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); 

这条线:

myResourceDictionary.Source = new Uri("C:\\Users\\Ash\\Documents\\Visual Studio 2010\\Projects\\moo Process Flow Manager\\moo Process Flow Manager\\Resources\\Styles\\ZoomBox.xaml"); 

在运行时抛出以下错误:

'Failed to create a 'Type' from the text 's:ZoomBox'.' Line number '5' and line position '12'. 

随着内部异常:

{"Type reference cannot find type named '{clr-namespace:Arkitec.moo.ProcessFlowManager.Controls}ZoomBox'."} 

这里是线这就是造成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}"> 

这里就是类被声明,它应该寻找在zoombox.cs:

namespace Arkitec.moo.ProcessFlowManager.Controls 
{ 
    public class ZoomBox : Control 
    { 

请让我知道你是否需要任何信息。

编辑:按照Guilammes answert我想:

myResourceDictionary.Source = new Uri("Resources/Styles/Shared.xaml", UriKind.Relative); 

但得到以下错误:

Cannot locate resource 'resources/styles/shared.xaml'. 
+0

我删除了我的答案,因为你编辑你的问题。我希望有人会帮助你更多 – Guillaume 2012-03-19 15:04:51

回答

0

尝试将shared.xaml属性设置如下:

Build Action --> Page 
copy to output directory --> do not copy 
custom tool --> MSBuild:Compile 

然后参考xaml如下

new System.Uri("/YourNamespace;Resources/Styles/Shared.xaml", System.UriKind.Relative);