日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
WPF窗口顏色變更方法

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

專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)上虞免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了近1000家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

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

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

WPF窗口顏色變更思路:

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

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

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

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

在本例中,WinWords窗體啟動(dòng)時(shí),自動(dòng)調(diào)用了ApplySkin方法來(lái)應(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)方法。


當(dāng)前標(biāo)題:WPF窗口顏色變更方法
文章URL:http://www.5511xx.com/article/coheooh.html