2012-11-14 58 views
2

我試圖讓我的應用程序(WPF)使用引用的程序集在我的App.xaml使用的Pack URI。在我的解決方案中,我有幾個項目。在基本應用程序中,我只有我的App.xaml。我希望這個使用引用程序集。C#的App.xaml和資源字典

叫我基地項目與項目的App.xaml 1(溶液)。這是App.xaml的相關部分:

<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="pack://application:,,,/MyProject.Project2;component/Themes/Generic.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

項目2有一個Generic.xaml文件夾「主題」。我很確定我正在使用Pack URI,因爲沒有使用Generic.xaml中的樣式(我正在使用自定義窗口覆蓋默認窗口,但它目前不工作。默認窗口樣式,窗口內的所有內容都是黑色的)。

文件夾層次結構:

MainFolder 
    Project 1 
     App.xaml 
     bin 
      Debug 
       Application.exe 
    Project 2 
     Themes 
      Generic.xaml 

問題:

  1. 有人能解釋pack://application:,,,語法?這一切意味着什麼?
  2. 我在做什麼錯的包URI?

在此先感謝。

+0

從MSDN包URI在WPF按照此 - http://msdn.microsoft.com/en-us/library/aa970069.aspx –

+0

@ RV1987我已經這樣做了,這裏的代碼或多或少直接從該頁面中拉出。 – tnw

回答

1

想通了。原來在MyProject.Project2我需要的AssemblyInfo.cs以下代碼:

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 
//(used if a resource is not found in the page, 
// or application resource dictionaries) 
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 
//(used if a resource is not found in the page, 
// app, or any theme specific resource dictionaries) 
)] 
1

的,,,後在包URI的第一項是組件的名稱。請確保您設置:

"pack://application:,,,/[ASSEMBLY name here];component/Themes/Generic.xaml"

+0

是的,程序集名稱設置正確。 – tnw

1

嘗試將資源字典到項目2,而不是在App.xaml中。