[英]WPF Style for Control Library
我有一个库( Styles.DLL
),其中包含键控WPF Styles
的集合。
我有一个类库( Module.DLL
),其中包含许多Windows
和可以在各种应用程序之间共享的UserControls
。 我使用Styles.DLL
定义的键控Styles
为这些Windows
和UserControls
例如Button
或ComboBox
上使用的各种Controls
创建隐式Styles
。
然后,我有了一个应用程序( App.EXE
),其中使用了Module.DLL
定义的Windows
。 我从Styles.DLL
的App.xaml
的App.EXE
合并所需的ResourceDictionaries
。
所有这一切。
我的问题是: 如何才能从托管应用程序中的App.xaml中删除合并的字典,并将其包含在Module.DLL中,而不必将字典合并到每个Window的资源中?
我想我正在寻找app.xaml
文件之类的东西,但在寻找类库...
我使用一种清除当前词典并合并所需词典的方法。 实际上,必须在方法调用时在内部设置“清除”,这是一个示例:
void AddResourceDictionary(string source)
{
ResourceDictionary resourceDictionary = Application.LoadComponent(new Uri(source, UriKind.RelativeOrAbsolute)) as ResourceDictionary;
Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
}
实施自定义主题/皮肤/资源:
private void ThemeNameHere()
{
Application.Current.Resources.Clear();
AddResourceDictionary("Computar.Wpf;component/Style/MyStyle.xaml");
....
}
这非常有帮助!
我找不到仅使用XAML
解决此问题的方法。 我的解决方案是使用以下代码将所需的ResourceDictionaries
合并到代码中的Application
对象中:
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
{
Source = new Uri(@"pack://application:,,,/Styles.DLL;component/Styles.xaml")
});
希望这对遇到类似问题的人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.