日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
對(duì)于WPF動(dòng)態(tài)換膚研究方案

WPF工具幫助開發(fā)人員簡(jiǎn)單的實(shí)現(xiàn)了一些制作精美圖形界面的功能需求。在WPF動(dòng)態(tài)換膚異常方便,只有將窗口資源設(shè)置為不同的ResourceDictionary就可以了。而且可以換得很徹底,甚至是徹底改變整個(gè)窗口上控件的種類,大小,個(gè)數(shù)等。#t#

創(chuàng)新互聯(lián)客戶idc服務(wù)中心,提供成都服務(wù)器托管、成都服務(wù)器、成都主機(jī)托管、成都雙線服務(wù)器等業(yè)務(wù)的一站式服務(wù)。通過(guò)各地的服務(wù)中心,我們向成都用戶提供優(yōu)質(zhì)廉價(jià)的產(chǎn)品以及開放、透明、穩(wěn)定、高性價(jià)比的服務(wù),資深網(wǎng)絡(luò)工程師在機(jī)房提供7*24小時(shí)標(biāo)準(zhǔn)級(jí)技術(shù)保障。

下面是一個(gè)WPF動(dòng)態(tài)換膚實(shí)現(xiàn)的方法。
建立一個(gè)叫做Blue.xaml的文件,在上面寫入

  1. < ResourceDictionary xmlns=
    "http://schemas.microsoft.com
    /winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft
    .com/winfx/2006/xaml"
  3. >
  4. < StackPanel x:Key="Root" Height="120">
  5. < Button Background="Blue" Height="40"/>
  6. < Button Background="Blue" Height="40"/>
  7. < Button Background="Blue" Height="40"/>
  8. < /StackPanel>
  9. < /ResourceDictionary>

然后建立一個(gè)叫Green.xaml的文件,在上面寫入

 
 
 
  1. < ResourceDictionary xmlns="http:
    //schemas.microsoft.com/winfx/2006
    /xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.
    com/winfx/2006/xaml"
  3. >
  4. < Grid x:Key="Root" Width="170" 
    Height="90">
  5. < Grid.ColumnDefinitions> 
  6. < ColumnDefinition Width="80"/>
  7. < ColumnDefinition Width="80"/>
  8. < /Grid.ColumnDefinitions>
  9. < Grid.RowDefinitions>
  10. < RowDefinition Height="40"/>
  11. < RowDefinition Height="40"/>
  12. < /Grid.RowDefinitions>
  13. < Button Background="Green" 
    Grid.Column="0" Grid.Row="0"/>
  14. < Button Background="Green" 
    Grid.Column="1" Grid.Row="0"/>
  15. < Button Background="Green" 
    Grid.Column="0" Grid.Row="1"/>
  16. < Button Background="Green" 
    Grid.Column="1" Grid.Row="1"/>
  17. < /Grid>
  18. < /ResourceDictionary>

然后是主窗口的xaml

 
 
 
  1. < Window x:Class="SkinTest2.
    Window1"
  2. xmlns="http://schemas.microsoft
    .com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft
    .com/winfx/2006/xaml"
  4. Title="Window1" Height="150" 
    Width="300" Content="{Dynamic
    Resource Root}">
  5. < /Window>

將窗口的Content設(shè)置為一個(gè)動(dòng)態(tài)資源Root就行了。
添加一個(gè)新類
Blue,在它的構(gòu)造函數(shù)中設(shè)置將Blue.xaml中的ResourceDictionary設(shè)置給窗口

 
 
 
  1. ResourceDictionary resDic =
     new ResourceDictionary();
  2. resDic.Source = new Uri
    ("Blue.xaml", UriKind.Relative);
  3. window.Resources = resDic;

StackPanel stackPanel = window.Content as StackPanel;
通過(guò)轉(zhuǎn)型來(lái)得到Blue中的StackPanel, 這種WPF動(dòng)態(tài)換膚方法看起來(lái)有的粗魯,但是沒有想到別的辦法

 
 
 
  1. for (int i = 0; i 
    <  stackPanel.Children.
    Count; i++)
  2. {
  3. button[i] = stackPanel.
    Children[i] as Button;
  4. button[i].Click += 
    handler[i];
  5. }

遍歷stackPanel的子元素,把Button一個(gè)個(gè)地取出來(lái)添加事件。沒法子。在寫B(tài)lue.xaml中的ResourceDictionary的時(shí)候不能給資源StackPanel的子元素再設(shè)置x:key了
添加一個(gè)Green類,同樣這么干。

***測(cè)試一下,在主窗口中放入一個(gè)托盤按鈕,方便一會(huì)切WPF動(dòng)態(tài)換膚

 
 
 
  1. private Blue blue;
  2. private Green green;
  3. private System.Windows.
    Forms.NotifyIcon notifyIcon;
  4. }
  5. public Window1()
  6. {
  7. InitializeComponent();
  8. notifyIcon = new System.
    Windows.Forms.NotifyIcon();
  9. notifyIcon.Icon = Properties.
    Resources.icon2;
  10. System.Windows.Forms.
    ContextMenu contextMenu = 
    new System.Windows.Forms.
    ContextMenu();

給contextMenu添加兩個(gè)菜單項(xiàng)

 
 
 
  1. contextMenu.MenuItems
    .Add("Blue").Click +=
  2. ((sender, e) => 
  3. if (blue == null)
  4. blue = new Blue(this); 
  5. green = null; 
  6. });

 
 
 
  1. contextMenu.MenuItems.
    Add("green").Click += 
  2. ((sender, e) => 
  3. {
  4. if(green == null)
  5. green = new Green(this); 
  6. blue = null; 
  7. }
  8. });

這里用了3.0中的Lambda表達(dá)式,看起來(lái)還不賴,比起boost中的那個(gè)類庫(kù)級(jí)的Lambda看起來(lái)自然多了。

 
 
 
  1. notifyIcon.ContextMenu 
    = contextMenu;
  2. notifyIcon.Visible 
    = true;

右擊托盤圖標(biāo),可以任意切換。當(dāng)然WPF動(dòng)態(tài)換膚換得這么徹底也很少見,都換了,和新建一個(gè)窗口有啥區(qū)別


本文名稱:對(duì)于WPF動(dòng)態(tài)換膚研究方案
瀏覽路徑:http://www.dlmjj.cn/article/dpgpeep.html