【发布时间】:2017-12-04 16:24:39
【问题描述】:
目标:
我有一个 WPF 项目,该项目应使用 DevExpress 主题进行主题化。 有一个 Login-UserControl 应该有一个主题背景图像。
实施
我制作了一个自定义主题。在那个主题中,我有一个文件夹“CustomResources”,其中有一个图像,我们称之为“Background.png”和一个定义 ImageBrush 的“Brushes.xaml”,如下所示:
<ResourceDictionary ...>
<ImageBrush x:Key="{CustomThemeKeyAssembly:CustomThemeResourcesThemeKey ResourceKey=LoginBackgroundImageBrush, ThemeName=CustomTheme}" ImageSource="Background.png" />
</ResourceDictionary>
因此,我有一个共享程序集CustomThemeKeyAssembly,它派生了一个自定义 ResourceThemeKey。
在项目中,我使用ApplicationThemeHelper注册并设置主题
var theme = new Theme("CustomTheme")
{
AssemblyName = "DevExpress.Xpf.Themes.CustomTheme.v17.2"
};
Theme.RegisterTheme(theme);
ApplicationThemeHelper.ApplicationThemeName = "CustomTheme";
我通过
引用资源Background="{dxci:ThemeResource ThemeKey={CustomThemeKeyAssembly:CustomThemeResourcesThemeKey ResourceKey=LoginBackgroundImageBrush}}"
根据 DevExpress 知识库/支持的建议。
问题
如果我像这样添加合并的资源字典,则只会找到并显示资源:
ResourceDictionary loginBackgroundDictionary = new ResourceDictionary
{
Source = new Uri($"pack://application:,,,/{MyProject.Properties.Settings.Default.ThemeAssembly};Component/CustomResources/Brushes.xaml", UriKind.Absolute)
};
//Add LoginBackgroundImageBrush Dictionary
Resources.MergedDictionaries.Add(loginBackgroundDictionary);
不过,没有文章或示例提到必须这样做。所以我的印象是我要么做错了什么,要么我错过了一些简单的步骤,比如将 Brushes.xaml 合并到一些 ResourceDictionary 中。
如果没有该 sn-p,我会收到一条警告,指出找不到资源。
问题
有没有人知道我哪里出错了,或者在没有最后一个 sn-p 的情况下我错过了什么?
仅供参考:我使用的是 DevExpress 17.2.3,ResourceKey 程序集针对 .net Framework 4.0
编辑
同时,我尝试将 Brushes.xaml 添加到主题程序集中的 Themes/Generic.xaml 中,如下所示:
<ResourceDictionary.MergedDictionaries>
<dxt:ResourceDictionaryEx Source="/DevExpress.Xpf.Themes.Office2016WhiteSE.v17.2;component/Themes/ControlStyles.xaml" />
<dxt:ResourceDictionaryEx Source="/DevExpress.Xpf.Themes.Office2016WhiteSE.v17.2;component/CustomResources/Brushes.xaml" />
</ResourceDictionary.MergedDictionaries>
没有任何区别。与以前的行为相同。
【问题讨论】:
-
@mm8 是的,我做到了。查看更新的问题。
-
@mm8 如果你有兴趣:我解决了。见答案。
标签: c# wpf xaml devexpress