對於我的應用程序主題,我創建了一個單獨的類庫MyApp.mes.dll。 在這個庫的根文件夾我有Standard.xaml:單獨程序集中的全局風格
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/MyApp.Themes;component/Standard/Accordion.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
在標準文件夾中我有Accordion.xaml:
<ResourceDictionary xmlns:layoutPrimitivesToolkit="..."
xmlns:layoutToolkit="..."
...>
<!-- layoutPrimitivesToolkit:AccordionButton -->
<Style TargetType="layoutPrimitivesToolkit:AccordionButton">
...
</Style>
...
</ResourceDictionary>
這是默認樣式WPF工具包手風琴控制,除了風格爲 AccordionItem被修改爲將背景設置爲透明(而不是藍色,這是一個已知的錯誤)。
對於這兩個xaml文件,Build Action設置爲「Resource」。 現在,MyApp的WPF項目引用MyApp.Themes庫後,在App.xaml中我寫道:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/MyApp.Themes;component/Standard.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
它不工作(沒有錯誤,只是風格不適用)。如果我複製&直接在App.xaml中粘貼Accordion.xaml樣式,那麼它可以工作。 有人建議增加僞資源字典,所以我增加了以下在App.xaml中MergedDictionaries結束標記後:
<Style TargetType="{x:Type layoutToolkit:AccordionItem}" />
再次,這是行不通的。有人可以幫我解決這個問題嗎?順便說一句,我沒有嘗試其他人建議的方法 - 使用basedOn。如果我必須那樣做,我想在MyApp.Themes中做, ,因爲它使App.xaml中使用主題更好。先謝謝你。
UPDATE1:它的工作原理,如果我直接複製粘貼&內容Accordion.xaml到Standard.xaml
UPDATE2:我想當地組裝的資源文件URI(http://msdn.microsoft.com/en-us/庫/ aa970069.aspx)在Standard.xaml:
<ResourceDictionary Source="pack://application:,,,/Standard/Accordion.xaml"/>
它拋出一個錯誤,說找不到標準/ accordion.xaml。