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 resources when the program loads into memory, and then no longer accesses the resource; dynamic resources (DynamicResource) Use refers to accessing resources while the program is running.
Related Downloads (code, screen Recorder): Http://pan.baidu.com/s/1c0q2BVM
online play : http://v.youku.com/v_show/id_XODE4MTI1MzYw.html
Warm tip : If the screen recording and code can not be downloaded, you can leave a message in the station, or send an email to [email protected]
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></Window>
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)