2011-10-07 56 views
2

基本上,我想將所有的XAML資源保留在外部程序集中(用於我的樣式)。我在我的應用程序中有這個外部程序集的參考。StaticResource其中資源在外部程序集中?

有沒有什麼衛星程序集或whatnot或如何去訪問這些樣式,以便我的應用程序仍然可以有StaticResource標籤沒有編譯錯誤?

回答

4

假設您在另一個程序集中將自己的樣式保存在ResourceDictionary中,則只需將其與當前資源(無論它們位於WindowUserControl或其他什麼)合併即可。

如果我們假設

  • 你的其他組件被命名爲 'external.assembly.name'
  • ResourceDictionary正在命名空間資源;和
  • 字典被命名爲 'MyStyles.xaml'

...那麼你可以合併的字典如下:

<UserControl.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary 
       Source="pack://application:,,,/external.assembly.name;component/Resources/MyStyles.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
     <!-- other resources go here --> 
    </ResourceDictionary> 
</UserControl.Resources>