2012-03-19 149 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);