在獨立的檔案中定義WPF資源,獨立定義wpf資源

來源:互聯網
上載者:User

在獨立的檔案中定義WPF資源,獨立定義wpf資源


一、文章概述

本示範介紹如何在單獨的檔案中定義WPF資源,並在需要的地方調用相關資源檔。
相關下載(代碼、螢幕錄影):http://pan.baidu.com/s/1sjO7StB
線上播放:http://v.youku.com/v_show/id_XODExODg0MzIw.html
溫馨提示:如果螢幕錄影和代碼不能正常下載,可站內留言,或發郵件到524130780@QQ.COM

二、首先在單獨的檔案中定義資源
XAML代碼如下所示:
<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">路漫漫其修遠兮,吾將上下而求索!</sys:String></ResourceDictionary>

三、在使用資源的地方串連到獨立的資源檔上
XAML代碼如下:
<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>

按照如上的代碼操作,就算是搞定了!
wpf中,怎引用其他xaml檔案中的Resources

把樣式資源寫到APP.XAML中。定義資源名稱,在使用時綁定就可以了。
 
WPF中的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 button1_Click(object sender, EventArgs e)
{
if (t1.ThreadState == ThreadState.Aborted||t1.ThreadState==ThreadState.Stopped)
{
MessageBox.Show("線程1結束了");
t1.Abort();
}
if (t2.ThreadState == ThreadState.Aborted||t1.ThreadState==ThreadState.Stopped)
{
MessageBox.Show("線程2結束了");
t2.Abort();
}
}
private void T1()
{
MessageBox.Show("進程1");

}
private void T2()
{
MessageBox.Show("進程2");

}
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.