DevExpress 15.1 WPF - 应用自定义主题

时间:2015-07-24 22:59:50

标签: c# wpf devexpress devexpress-wpf

将自定义主题应用于DevExpress 15.1 WPF应用程序时遇到问题。

我已经完成了步骤:

  • 使用DevExpress主题编辑器(最新版本)
  • 创建基于Metropolis Light的新主题
  • 编译
  • 在我的应用程序中添加对已编译dll的引用
  • 在我的MainWindow中添加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);

结果是例外:

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中发生了变化?

1 个答案:

答案 0 :(得分:0)

你非常接近。

我将以下代码添加到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;