c# - 何时加载 Generic.xaml 样式?

标签 c# wpf xaml styles

我想知道在应用程序启动后何时加载存储在 Generic.xaml 文件中的 Style,并且在加载完成后,这种情况发生的频率如何.我的意思是它们是只加载一次还是每次实例化 Control 的新对象时加载?此外,Style-Resource 真正从资源文件中读取的频率是多少?

最佳答案

I. 我的意思是它们只加载一次还是每次实例化控件的新对象时加载?

Style'sResourceDictionary 仅在程序开始时加载一次。引自 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 真正从资源文件中读取的频率是多少?

每个StyleResourceDictionary都被编译成BAML代码,这些资源是程序集的一部分。所有程序集都由 JIT 编译器(在启动时)加载到内存中一次,进一步的工作是在内存中应用。我的意思是,我不认为应用程序每次读取文件样式时,根据 JIT 编译器的逻辑,所有内容都以元数据的形式存储在内存中,后续处理必须在内存中进行.

关于JIT-compiler的工作,关于.NET的工作,可以看一篇精彩book Jeffrey Richter 的作者。

关于c# - 何时加载 Generic.xaml 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18944109/

相关文章:

c# - 在 XAML 中显示矩阵

c# - 将字节数组转换为字符串然后再返回会产生不同的结果

c# - 带有可折叠项目的 ListView?

wpf - 如何保持用户控制?

.net - 如何让 System.Windows.ShowDialog() 返回 'true' ?

c# - 更改窗口大小 UWP 时更改控件大小布局

visual-studio - Visual Studio 2012 无法识别 Xaml 文件,设计 View 已损坏

c# - Microsoft Media Platform + 表单例份验证

c# - 将拖放限制在单个控件内

c# - 为 TreeView 和 TreeViewItem 触发的 ContextMenuOpening 事件