What are StaticResources and DynamicResources in WPF?

2

When I use resources in WPF, I can specify them as StaticResource , as DyanamicResource . However, most of the time only one works, and the other would start an exception.

From this point, I have the following doubts:

  • What is a StaticResource and what is a DynamicResource ?
  • When should I use each?
  • Why does not UWP allow you to use DynamicResources ?
asked by anonymous 24.12.2016 / 19:00

1 answer

1

StaticResource loads soon on XAML load and does not is more modified. It is preferred because it gives more performance. The entire WPF mechanism knows that it does not need to be monitoring it.

DynamicResource is an expression (it's like a variable) which indicates what the resource is, then you have the flexibility to change at run time which resource is used. Your load effectively occurs only when the resource needs to be used, so it can even be a resource to be created. Just change what will result in the expression that the resource may be different. A change will trigger changes across the entire screen tree.

In Microsoft documentation has a list of scenarios in that it can be used.

Idonothaveconclusiveinformation,butitseemsthattherearenodynamicfeaturesinUWPbecausetheyhavelearnedthatitbringsmoreproblemthanbenefits. This can be useful .

    
24.12.2016 / 19:18