Define and search for WPF object-level resources, and search for wpf object definitions

Source: Internet
Author: User
Tags mscorlib

Define and search for WPF object-level resources, and search for wpf object definitions

Article Overview:

This example describes how to define WPF object-level resources and access and use object-level resources through XAML code and C.

Related downloads (Code, screen recording): Http://pan.baidu.com/s/1hqvJNY8

Online playback: http://v.youku.com/v_show/id_XODA1NTU2Mzky.html

Tip: If the screen recording and Code cannot be properly downloaded, you can leave a message in the station, or mail to the 524130780@QQ.COM


1. Complete definition and use of resources

<Window x: Class = "Demo008.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml" xmlns: sys = "clr-namespace: System; assembly = mscorlib "Title =" Resource "FontSize =" 16 "Loaded =" Window_Loaded "> <! -- The complete Writing Method --> <Window. Resources> <ResourceDictionary> <sys: String x: Key = "str"> sailing on the side of a boat, The Health tree is everywhere. </Sys: String> <sys: Double x: Key = "dbl"> 3.1415926 </sys: Double> </ResourceDictionary> </Window. resources> <StackPanel> <TextBlock Margin = "5" Text = "{StaticResource ResourceKey = str}"/> </StackPanel> </Window>

Ii. Short resource definition and use
<Window x: Class = "Demo008.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml" xmlns: sys = "clr-namespace: System; assembly = mscorlib "Title =" Resource "FontSize =" 16 "Loaded =" Window_Loaded "> <! -- Short for --> <Window. Resources> <sys: String x: Key = "str"> sailing on the side of a boat, the disease is everywhere. </Sys: String> <sys: Double x: Key = "dbl"> 3.1415926 </sys: Double> </Window. resources> <StackPanel> <TextBlock x: Name = "TextBlock1" Margin = "5" Text = "{StaticResource str}"/> </StackPanel> </Window>

Iii. Search for resources by code
The common practice is as follows:
string text = this.FindResource("str").ToString();this.TextBlock1.Text = text;

If you know which object the resource belongs to, you can directly access the resource dictionary using the following method:
string text = this.Resources["str"].ToString();this.TextBlock1.Text = text;



I want to compete first

You can't do it anymore. You only have to fight for the third place.

Resource reference between different projects in xaml

Thread t1 = null;
Thread t2 = null;
Private void Form1_Load (object sender, EventArgs e)
{
T1 = new Thread (new ThreadStart (T1 ));
T1.Start ();
T2 = new Thread (new ThreadStart (T2 ));
T2.Start ();
}

Private void button#click (object sender, EventArgs e)
{
If (t1.ThreadState = ThreadState. Aborted | t1.ThreadState = ThreadState. Stopped)
{
MessageBox. Show ("thread 1 is finished ");
T1.Abort ();
}
If (t2.ThreadState = ThreadState. Aborted | t1.ThreadState = ThreadState. Stopped)
{
MessageBox. Show ("thread 2 is finished ");
T2.Abort ();
}
}
Private void T1 ()
{
MessageBox. Show ("process 1 ");

}
Private void T2 ()
{
MessageBox. Show ("process 2 ");

}

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.