I. Overview of the article
This presentation describes the basic use of static and dynamic resources for WPF, and makes a simple comparison of both.
A static resource (StaticResource) refers to a one-time use of a resource when the program is loaded into memory, and then no longer accesses the resource; dynamic resource (DynamicResource) usage refers to accessing resources while the program is running.
Ii. definition and use of resources
<window x:class= "Demo010.mainwindow" xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml" Title= "MainWindow" height= "149" width= "296" > <Window.Resources> <textblock x:key= "Res1" text= " Sea Bright Moon "/> <textblock x:key=" Res2 "text=" Sea Bright moon "/> </Window.Resources> <stackpanel > <button margin= "5,5,5,0" content= "{StaticResource Res1}"/> <button margin= "5,5,5,0" content= " {DynamicResource Res2} "/> <button margin=" 5,5,5,0 "content=" Update "click=" Updateres_click "/> </StackPanel>
Ii. updating the content of resources
private void Updateres_click (object sender, RoutedEventArgs e) {this . resources["Res1"] = new TextBlock () {Text = "Tianya total at this time"}; This. resources["Res2"] = new TextBlock () {Text = "Tianya total at this time"}; }
Iii. changes before and after renewal of resources
[WPF] Static resources (StaticResource) and dynamic resources (DynamicResource)