偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

WPF窗口顏色變更方法

開發(fā) 開發(fā)工具
WPF窗口顏色的變更需要?jiǎng)?chuàng)建一些資源文件愛你,并且還需要用到一些特定的語句來實(shí)現(xiàn)。本文中將會(huì)詳細(xì)的對(duì)此一一進(jìn)行描述。

WPF開發(fā)工具中有一種常用實(shí)現(xiàn)方法,就是窗口的操作。我們將會(huì)在這篇文章中為大家實(shí)現(xiàn)WPF窗口顏色的變更,希望對(duì)大家有所幫助。#t#

WPF窗口顏色目標(biāo):

動(dòng)態(tài)變更窗口的底色(當(dāng)然,可以擴(kuò)展為其他元素的樣式)

WPF窗口顏色變更思路:

創(chuàng)建兩個(gè)資源文件(Resource Dictionary),一個(gè)用來存放默認(rèn)樣式(Default.xaml),一個(gè)用來存放其他樣式(HotHot.xaml);

在需要變更樣式的窗體中(本例中為:WinWords),使用動(dòng)態(tài)樣式(... Style="{DynamicResource styleBcakground}")

在Application類中(方便調(diào)用),添加一個(gè)應(yīng)用樣式的公共方法(ApplySkin)

在主窗體中(本例是在WinWords窗體中通過按鈕點(diǎn)擊事件)調(diào)用Application中應(yīng)用樣式方法(ApplySkin)

在本例中,WinWords窗體啟動(dòng)時(shí),自動(dòng)調(diào)用了ApplySkin方法來應(yīng)用默認(rèn)的樣式(Default)

OK,WPF窗口顏色代碼如下:

  1. < HOME_DIR>\Resources\Skins
    \Default.xaml  
  2. < !-- Background Style --> 
  3. < Style x:Key="styleBackground"> 
  4. < Setter Property="Control.Background"> 
  5. < Setter.Value> 
  6. < LinearGradientBrush StartPoint=
    "0,0.5" EndPoint="1,0.5" Opacity="0.5"> 
  7. < GradientStop Color="LightSkyBlue"
     Offset="0" /> 
  8. < GradientStop Color=
    "WhiteSmoke" Offset="0.5" /> 
  9. < GradientStop Color="Light
    SkyBlue"
     Offset="1" /> 
  10. < /LinearGradientBrush> 
  11. < /Setter.Value> 
  12. < /Setter> 
  13. < /Style> 
  14. < HOME_DIR>\Resources\Skins\HotHot.xaml  
  15. < !-- Background Style --> 
  16. < Style x:Key="styleBackground"> 
  17. < Setter Property="Control.Background"> 
  18. < Setter.Value> 
  19. < LinearGradientBrush StartPoint=
    "0.5,0" EndPoint="0.5,1"> 
  20. < GradientStop Color="#50000000" 
    Offset="0.5" /> 
  21. < GradientStop Color="#ff999999" 
    Offset="1" /> 
  22. < /LinearGradientBrush> 
  23. < /Setter.Value> 
  24. < /Setter> 
  25. < /Style> 
  26. < HOME_DIR>\WinWords.xaml  
  27. < Grid Style="{DynamicResource 
    styleBackground}"
    > 
  28. < HOME_DIR>\WinWords.xaml.cs  
  29. public WinWords()  
  30. {  
  31. InitializeComponent();  
  32. this.ApplySkin("Default");  
  33. }  
  34. private void ApplySkin(string 
    pstrDictPath)  
  35. {  
  36. string skinDictPath = @".
    \Resources\Skins\" + pstrDictPath 
    + @".xaml";  
  37. Uri skinDictUri = new Uri(skinDict
    Path, UriKind.Relative);  
  38. MyCcApp app = Application.Current 
    as MyCcApp;  
  39. app.ApplySkin(skinDictUri);  
  40. }  
  41. private void btnTestSkining_Click
    (object sender, RoutedEventArgs e)  
  42. {  
  43. this.ApplySkin("HotHot");  
  44. }  
  45. < HOME_DIR>\MyCcApp.xaml.cs  
  46. public void ApplySkin(Uri 
    skinDictionaryUri)  
  47. {  
  48. ResourceDictionary skinDict =
     
    Application.LoadComponent(skin
    DictionaryUri) as ResourceDictionary;  
  49. Collection< ResourceDictionary> 
    mergedDicts = base.Resources.
    MergedDictionaries;  
  50. if (mergedDicts.Count > 0)  
  51. {  
  52. mergedDicts.Clear();  
  53. }  
  54. mergedDicts.Add(skinDict);  

上面介紹的內(nèi)容就是WPF窗口顏色的變更實(shí)現(xiàn)方法。

責(zé)任編輯:曹凱 來源: 博客園
相關(guān)推薦

2009-12-24 15:22:10

WPF繼承自定義窗口

2009-12-24 14:38:52

WPF全屏幕窗口

2009-12-25 09:44:52

WPF窗口設(shè)置

2009-12-25 10:05:06

WPF資源

2009-12-28 15:08:12

WPF字體

2009-12-25 14:35:34

WPF布局

2009-12-23 18:06:25

WPF模板

2009-12-24 14:18:57

WPF類型轉(zhuǎn)換

2009-12-24 16:36:06

WPF InkCanv

2009-12-28 17:33:19

WPF視頻音頻

2009-12-28 16:00:36

WPF樣式繼承

2009-12-24 17:57:53

WPF頁(yè)面跳轉(zhuǎn)

2009-12-24 18:09:23

WPF開發(fā)環(huán)境

2009-12-25 10:20:28

WPF窗口

2009-12-28 11:14:29

WPF顯示文本

2009-12-28 13:28:03

WPF視頻

2009-12-24 13:31:25

WPF UI設(shè)計(jì)

2009-12-23 17:57:22

WPF默認(rèn)模板

2009-12-23 15:03:52

WPF單元測(cè)試

2009-12-23 14:19:07

WPF單向綁定
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)