我有一个图书馆(Styles.DLL
) 其中包含带键的 WPF 集合Styles
.
我有一个班级图书馆(Module.DLL
)其中包含多个Windows
and UserControls
可以在各种应用程序之间共享。我用的是带键的Styles
定义于Styles.DLL
创造隐含的Styles
对于各种Controls
用在这些Windows
and UserControls
e.g. Button
or ComboBox
.
然后我有一个应用程序(App.EXE
),其中我使用Windows
定义于Module.DLL
。我合并所需的ResourceDictionaries
from Styles.DLL
in the App.xaml
of App.EXE
.
这一切都有效。
我的问题是:如何从托管应用程序的 App.xaml 中删除字典合并并将其包含在 Module.DLL 中,而无需将字典合并到每个窗口的资源中?
我想我正在寻找类似的东西app.xaml
文件,但对于类库...
我使用一种方法来清除当前词典并合并我想要的词典。实际上,“Clear”必须在方法调用时设置,下面是一个示例:
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");
....
}
这非常有帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)