DevExpress 15.1 WPF -应用自定义主题

本文关键字:自定义 应用 WPF DevExpress | 更新日期: 2023-09-27 18:04:47

我在DevExpress 15.1 WPF应用程序中应用自定义主题时遇到了麻烦。

我已经完成了以下步骤:

  • 使用DevExpress主题编辑器(最新版本)创建基于Metropolis Light的新主题
  • 编译它
  • 在我的应用程序中添加对编译后dll的引用
  • 将此添加到我的主窗口InitializeComponent()之前:

    Theme theme = new Theme("MyTheme", "DevExpress.Xpf.Themes.MyTheme.v15.1"); theme.AssemblyName = "DevExpress.Xpf.Themes.MyTheme.v15.1"; Theme.RegisterTheme(theme); ThemeManager.SetTheme(this, theme);

结果是exception:

An exception of type 'System.Reflection.TargetInvocationException' occurred in System.Xaml.dll but was not handled in user code
Additional information: Exception has been thrown by the target of an invocation

带内部异常

{"Object reference not set to an instance of an object."}
at DevExpress.Xpf.Core.ThemedElementsDictionary.GetAssemblyFullName(Object key)
at DevExpress.Xpf.Core.ThemedElementsDictionary.RegisterThemeType(String themeName, String fullName, Object key)
你知道我做错了什么吗?也许在15.1中发生了变化?

DevExpress 15.1 WPF -应用自定义主题

你很接近了。

我添加了以下代码到App.xaml.cs的OnStartup方法:

var myTheme = new Theme("Dark", "DevExpress.Xpf.Themes.Dark")
{
    AssemblyName = "DevExpress.Xpf.Themes.Dark.v15.1"
};
Theme.RegisterTheme(myTheme);
ThemeManager.ApplicationThemeName = myTheme.Name;