Is it possible to add one resource dictionary into other one? Thanks for any help.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
A snippet straight from a sketchflow project I am working on that shows how to merge resource dictionaries in xaml:
This shows merging two additional resource dictionaries into another resource dictionary.
(Note that the order can become important if you have default styles defined in more than one place as they will override each other)
Something like:
Might be what you're looking for. We use code like this in our Prism Modules.
In Dictionary2.xaml define MergedDictionaries (right after the opening ResourceDictionary tag):
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
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.
From answer to this question by XAMeLi