[WPF] Static resources, dynamic resources, and wpfstaticresource

Source: Internet
Author: User

[WPF] Static resources, dynamic resources, and wpfstaticresource

I. Overview

This demonstration introduces the basic usage of WPF static and dynamic resources, and makes a simple comparison between them.
StaticResource refers to the one-time usage of resources when the program loads the memory, and the resource is no longer accessed. Dynamic Resource) it means that resources are accessed during the running of the program.

Ii. Define and use 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 = ""/> <TextBlock x: key = "Res2" Text = "moon in the sea"/> </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, 0 "Content =" Update "Click =" UpdateRes_Click "/> </StackPanel> </Window>

  

Ii. update resource content

Private void UpdateRes_Click (object sender, RoutedEventArgs e) {this. resources ["Res1"] = new TextBlock () {Text = ""}; this. resources ["Res2"] = new TextBlock () {Text = ""};}

  

Iii. Changes Before and After resource update

Related Article

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.