我想知道在应用程序启动后何时加载存储在 Generic.xaml
文件中的 Style
,并且在加载完成后,这种情况发生的频率如何.我的意思是它们是只加载一次还是每次实例化 Control
的新对象时加载?此外,Style
-Resource 真正从资源文件中读取的频率是多少?
最佳答案
I.
我的意思是它们只加载一次还是每次实例化控件的新对象时加载?
Style's
、ResourceDictionary
仅在程序开始时加载一次。引自 link :
Every resource dictionaries under "Themes" directory under your project will be "compiled"(this compilation process is done by msbuild and the custom build tasks) into BAML representation, and those BAML files will be treated as resources files for the finally compiled assemblies.
Another benefit of themed assemblies is that you can use themed assembly to define resource-only or shared resource assembly, because the resource dictionaries within the themed assemblies will be loaded only once, this can give much more benefits than the ResourceDictionary.MergedDictonaries mechanism.
II.
此外,Style-Resource 真正从资源文件中读取的频率是多少?
每个Style
,ResourceDictionary
都被编译成BAML代码,这些资源是程序集的一部分。所有程序集都由 JIT 编译器(在启动时)加载到内存中一次,进一步的工作是在内存中应用。我的意思是,我不认为应用程序每次读取文件样式时,根据 JIT 编译器的逻辑,所有内容都以元数据的形式存储在内存中,后续处理必须在内存中进行.
关于JIT-compiler的工作,关于.NET的工作,可以看一篇精彩book
Jeffrey Richter
的作者。
关于c# - 何时加载 Generic.xaml 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18944109/