HerpDerpington
HerpDerpington

Reputation: 4483

When are the Generic.xaml-styles being loaded?

I wonder when after the application has started the Styles stored inside the Generic.xaml file are being loaded, and after this has been done, how often this happens. I mean are they loaded only once or every time a new object of the Control is being instantiated? Furthermore, how often is the Style-Resource really being read out of the resource file?

Upvotes: 3

Views: 199

Answers (1)

Anatoliy Nikolaev
Anatoliy Nikolaev

Reputation: 22702

I. I mean are they loaded only once or every time a new object of the Control is being instantiated?

Style's, ResourceDictionary are loaded only once, at the start of the program. Quote from 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. Furthermore, how often is the Style-Resource really being read out of the resource file?

Each Style, ResourceDictionary is compiled into BAML code, and these resources are part of the assembly. All assemblies are loaded into memory once by JIT-compiler (on the start), and further work is in application in memory. I mean, I do not think that the application every time a file reads styles, according to the logic of the JIT-compiler, everything is stored in memory in the form of meta-data, and the subsequent treatment must take place in the memory.

About the work of JIT-compiler and about the work .NET, you can read a wonderful book of Jeffrey Richter.

Upvotes: 3

Related Questions