如何导入一个的ResourceDictionary到其他,在WPF? [英] How to import one ResourceDictionary into other, in WPF?

查看:313
本文介绍了如何导入一个的ResourceDictionary到其他,在WPF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能增加一个资源字典到另一个?
感谢您的帮助。

Is it possible to add one resource dictionary into other one? Thanks for any help.

推荐答案

在Dictionary2.xaml定义MergedDictionaries(开放的ResourceDictionary标签之后):

In Dictionary2.xaml define MergedDictionaries (right after the opening ResourceDictionary tag):

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/Path/to/Dictionary1.xaml" />
</ResourceDictionary.MergedDictionaries>



这里有一个问题:每次合并字典时候你有效地创建合并字典的一个副本。而且它是递归的 - 如果你有Dict3.xaml和Dict4.xaml这两个负载Dictionary2.xaml,你将有Dictionary1.xaml的三个实例创建

there's a catch: each time you merge dictionaries you effectively create a copy of the merged dictionary. And it's recursive - if you have Dict3.xaml and Dict4.xaml that both load Dictionary2.xaml, you will have three instances of Dictionary1.xaml created

解决方案是一个 SharedResourceDictionary 。本教程中的实现应该被看作是一个起点,可能需要调整一些水平 - 根据使用场景。谷歌WPF SharedResourceDictionary一些陷阱和解决方案。

The solution is a SharedResourceDictionary. The implementation in the tutorial should be seen as a starting point and will probably need some level of tweaking - depending on use scenario. Google "wpf SharedResourceDictionary" for some gotchas and solutions.

这答案的这个问题通过 XAMeLi

这篇关于如何导入一个的ResourceDictionary到其他,在WPF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆