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 ");
}