0
我目前正面臨一個問題。我使用的是WPF.Themes,我在codeplex上找到它,它允許我改變我的應用程序的主題。將控件樣式與由另一個項目動態設置的全局樣式合併
所以我導入項目,並得到它一切工作正常,但對於一些控制,說我的treeViewItem,我已經設置了它的樣式,它覆蓋了全局樣式。
研究後我有下面的代碼,但仍然無法正常工作。
<TreeView Name="_tvTreeView" Grid.Row="1" >
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Type TreeViewItem}}">
<EventSetter Event="MouseDoubleClick" Handler="tvTreeView_PreviewMouseDoubleClick"/>
<EventSetter Event="MouseDown" Handler="tvTreeView_MouseDown"/>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
如果我在我的主項目的app.xaml的合併字典中手動添加resrouce文件,則基於作品。
但WPF.Themes項目允許我這樣做動態地改變主題。
public static void ApplyTheme(this ContentControl control, string theme)
{
ResourceDictionary dictionary = ThemeManager.GetThemeResourceDictionary(theme);
control.Resources.MergedDictionaries.Clear();
if (dictionary != null)
control.Resources.MergedDictionaries.Add(dictionary);
}
具有上述代碼,不會合並全局樣式和我的事件設置器。 如果我手動引用app.xaml中的主題,那麼「BasedOn」將啓動並工作,但如果我動態設置mergedictionaries,「BasedOn」似乎不起作用。
有沒有一種方法可以在不添加主題到app.xaml的情況下工作。
感謝和問候,