C#WPF dynamic resource and static resource application examples

This article demonstrates the application of dynamic resources and static resources in C# WPF

1. Resource overview

Static resources (StaticResource) refer to the one-time use of resources when the program is loaded into memory, and then the resource is no longer accessed.

Dynamic resources (DynamicResource) refer to resources that are accessed during the running of the program.

In WPF, each interface element contains an attribute named Resources, which stores resources in the form of "key-value" pairs, and its child elements will find these resources from Resources when using these resources.

Resources referenced in child-level elements are divided into StaticResource and DynamicResource. The difference between the two is that StaticResource cannot be changed after the program is compiled, while DynamicResource can be modified after the compilation is completed.

2. Examples

First create a WPF project and add 3 buttons

Guess you like

Origin blog.csdn.net/qq_30725967/article/details/133385157
Recommended