Define WPF resources in independent files and define wpf resources independently.

Source: Internet
Author: User

Define WPF resources in independent files and define wpf resources independently.


I. Overview

This example shows how to define WPF resources in a separate file and call related resource files as needed.
Related downloads (Code, screen recording): Http://pan.baidu.com/s/1sjO7StB
Online playback: Http://v.youku.com/v_show/id_XODExODg0MzIw.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

2. Define resources in a separate file
The XAML code is as follows:
<ResourceDictionary 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"> <sys: String x: key = "text"> the road is long, so I will go up and down to seek help! </Sys: String> </ResourceDictionary>

3. connect to an independent resource file where resources are used
The XAML code is as follows:
<Window x:Class="Demo009.MainWindow"        xmlns="http://sche1mas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="Resource Files" FontSize="30">    <Window.Resources>        <ResourceDictionary Source="ShinyRed.xaml" />    </Window.Resources>    <StackPanel>        <TextBlock Text="{StaticResource text}" />    </StackPanel></Window>

If you follow the above code, you can get it done!
How to reference Resources in other xaml files in wpf

Write the style resource to APP. XAML. Define the resource name. You can bind it when using it.

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.