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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
WPF圖標(biāo)特殊效果實現(xiàn)方法

WPF開發(fā)工具的用途主要是體現(xiàn)在各種圖形界面的顯示方面。那么在使用的過程中,其中有很多技巧值得我們?nèi)ド钊胙芯?。本篇將要實現(xiàn)圖標(biāo)的兩個效果:1. 顯示圖標(biāo)標(biāo)簽,2. 圖標(biāo)模糊效果。#t#

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

在上一篇中提到Image沒有HTML < img>的Title屬性(在MSDN中也沒找到類似的屬性),所以本篇將自行制作一個標(biāo)簽,它的功能是當(dāng)鼠標(biāo)移動到圖標(biāo)上方時會顯示該圖標(biāo)的Tag說明,并且該WPF圖標(biāo)模糊顯示。

1. 在Home < Image>中加入MouseEnter和MouseLeave事件。

  1. < Image Source="image/home.png" 
  2. Width="110" Height="110" 
  3. Tag="My Home"Canvas.Left="30"
    Canvas.Top="20" 
  4. Cursor="Hand" 
  5. MouseEnter="Image_BlurEffect_MouseEnter" 
  6. MouseLeave="Image_BlurEffect_MouseLeave">
  7. < /Image>

2. 事件加好了,就要為添加內(nèi)容了。先看Image_BlurEffect_MouseEnter事件:

 
 
 
  1. private void Image_BlurEffect_
    MouseEnter(object sender,
    MouseEventArgs e) 
  2. { 
  3. //將sender定義為Image對象 
  4. Image image = sender as Image;
  5. //創(chuàng)建模糊BlurEffect對象 
  6. BlurEffect newBlurEffect = 
    new BlurEffect();
  7. //設(shè)定模糊效果值Radius 
  8. newBlurEffect.Radius = 5;
  9. //為Image添加Blur效果 
  10. image.Effect = newBlurEffect;
  11. //將Image Tag內(nèi)容傳給imageTitle 
    Textblock 
  12. imageTitle.Text = " " + 
    image.Tag.ToString() +" ";
  13. //將imageTitle的Border設(shè)置為可見 
  14. imageTitleBorder.Visibility = 
    Visibility.Visible;
  15. //調(diào)整imageTitleBorder的Canvas位置,
    使其在圖標(biāo)下方顯示 
  16. Canvas.SetLeft(imageTitleBorder, 
    Canvas.GetLeft(image)+ image.
    Width / 2 - 15); 
  17. Canvas.SetTop(imageTitleBorder, 125); 
  18. }
  19. private void Image_BlurEffect_
    MouseLeave(object sender,
    MouseEventArgs e) 
  20. { 
  21. Image image = sender as Image; 
  22. BlurEffect newBlurEffect = 
    new BlurEffect(); 
  23. newBlurEffect.Radius = 0; 
  24. image.Effect = newBlurEffect; 
  25. imageTitleBorder.Visibility = 
    Visibility.Collapsed; 
  26. }

可以使用ToolTipService。經(jīng)過測試使用ToolTip可以實現(xiàn)標(biāo)簽的功能(代碼如下),而且也不用預(yù)設(shè)WPF圖標(biāo)顯示效果,但是沒法通過Canvas設(shè)定其位置,大家可以都學(xué)習(xí)一下。

 
 
 
  1. XAML:
  2. < Image Source="image/home.png" 
    Width="110" Height="110" 
  3. Tag="My Home" Canvas.Left="30" 
    Canvas.Top="20" 
  4. MouseEnter="Image_BlurEffect_
    MouseEnter" 
  5. MouseLeave="Image_BlurEffect_
    MouseLeave" 
  6. Cursor="Hand"> 
  7. < Image.ToolTip> 
  8. < TextBlock>My Home< /TextBlock> 
  9. < /Image.ToolTip> 
  10. < /Image>

C#代碼自然就簡單多了:

 
 
 
  1. private void Image_BlurEffect_
    MouseEnter(object sender,
    MouseEventArgs e) 
  2. { 
  3. Image image = sender as Image; 
  4. BlurEffect newBlurEffect = 
    new BlurEffect(); 
  5. newBlurEffect.Radius = 5; 
  6. image.Effect = newBlurEffect; 
  7. }

上面這些方法介紹的就是WPF圖標(biāo)顯示效果的實現(xiàn)。


文章名稱:WPF圖標(biāo)特殊效果實現(xiàn)方法
網(wǎng)頁網(wǎng)址:http://www.dlmjj.cn/article/djcjdip.html