[WPF] Static resources (StaticResource) and dynamic resources (DynamicResource)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.