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

Silverlight拖放功能相關(guān)應(yīng)用技巧分享

開發(fā) 開發(fā)工具
如果我們想要實(shí)現(xiàn)Silverlight拖放功能,首先需要做的就出發(fā)一些相關(guān)事件,這些事件包括:MouseLeftButtonDown事件;MouseMove事件;MouseLeftButtonUp事件等等。

Silverlight工具是一個(gè)非常有用的開發(fā)工具。可以幫助開發(fā)人員輕松實(shí)現(xiàn)基于多媒體播放操作等功能。在實(shí)際使用中,我們會體會到其強(qiáng)大的功能特定。在這里就先來了解其中Silverlight拖放功能的作用。#t#

在Silverlight拖放功能的實(shí)現(xiàn)中,分為三個(gè)步驟:

1.按下鼠標(biāo),觸發(fā)MouseLeftButtonDown事件,選擇要拖動的對象。

2.移動鼠標(biāo),觸發(fā)MouseMove事件,移動選擇的對象。

3.放開鼠標(biāo),觸發(fā)MouseLeftButtonUp事件,停止捕捉事件。

做一個(gè)簡單的界面,用一個(gè)按鈕來顯示Silverlight拖放功能,如下XAML聲明:

  1. < Canvas Background="#46461F"> 
  2. < Button   
  3. MouseLeftButtonDown="OnMouseDown"   
  4. MouseMove="OnMouseMove" 
  5. MouseLeftButtonUp="OnMouseUp"   
  6. Canvas.Left="50" Canvas.Top="50"
     Background="Red" 
  7. FontSize="18" 
  8. Width="160" Height="80"> 
  9. < Button.Content> 
  10. < StackPanel Orientation=
    "Horizontal" HorizontalAlignment
    ="Center" 
  11. VerticalAlignment="Center"> 
  12. < Image Source="smile_6.png">< /Image> 
  13. < TextBlock Text="拖動我" 
    VerticalAlignment="Center"
     Margin="10">< /TextBlock> 
  14. < /StackPanel> 
  15. < /Button.Content> 
  16. < /Button> 
  17. < /Canvas> 

這里為了界面顯示效果,使用了控件模板,后續(xù)會專門講到。

Silverlight拖放功能之開始拖放操作

開始拖放操作,實(shí)現(xiàn)MouseLeftButtonDown事件處理程序,用兩個(gè)全局變量來記錄當(dāng)前鼠標(biāo)的位置和鼠標(biāo)是否保持移動。

 

  1. bool trackingMouseMove = false;  
  2. Point mousePosition;  
  3. void OnMouseDown(object sender, 
    MouseButtonEventArgs e)  
  4. {  
  5. FrameworkElement element = sender 
    as FrameworkElement;  
  6. mousePosition = e.GetPosition(null);  
  7. trackingMouseMove = true;  
  8. if (null != element)  
  9. {  
  10. element.CaptureMouse();  
  11. element.Cursor = Cursors.Hand;  
  12. }  

Silverlight拖放功能之移動對象

移動對象,實(shí)現(xiàn)MouseMove事件處理程序,計(jì)算元素的位置并更新,同時(shí)更新鼠標(biāo)的位置。

 

  1. void OnMouseMove(object sender, 
    MouseEventArgs e)  
  2. {  
  3. FrameworkElement element = 
    sender as FrameworkElement;  
  4. if (trackingMouseMove)  
  5. {  
  6. double deltaV = e.GetPosition(null).
    Y - mousePosition.Y;  
  7. double deltaH = e.GetPosition(null).
    X - mousePosition.X;  
  8. double newTop = deltaV + (double)
    element.GetValue(Canvas.TopProperty);  
  9. double newLeft = deltaH + (double)
    element.GetValue(Canvas.LeftProperty);  
  10. element.SetValue(Canvas.TopProperty, newTop);  
  11. element.SetValue(Canvas.LeftProperty, newLeft);  
  12. mousePosition = e.GetPosition(null);  
  13. }  

Silverlight拖放功能之完成拖放操作

完成拖放操作,實(shí)現(xiàn)MouseLeftButtonUp事件處理程序。

 

  1. void OnMouseUp(object sender, 
    MouseButtonEventArgs e)  
  2. {  
  3. FrameworkElement element = 
    sender as FrameworkElement;  
  4. trackingMouseMove = false;  
  5. element.ReleaseMouseCapture();  
  6. mousePositionmousePosition.X = 
    mousePosition
    .Y = 0;  
  7. element.Cursor = null;  

 

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

2009-12-29 16:08:41

Silverlight

2009-12-29 17:56:47

Silverlight

2009-12-30 18:23:13

Silverlight

2009-12-30 13:37:24

Silverlight

2009-12-31 17:00:40

Silverlight

2010-01-04 14:35:55

Silverlight

2009-12-30 18:18:32

Silverlight

2009-12-31 10:21:53

Silverlight

2009-12-31 16:44:53

Silverlight

2009-12-30 09:55:51

Silverlight

2010-01-28 10:55:14

Android電源管理

2010-01-04 14:49:30

Silverlight

2010-03-04 14:39:52

Python讀取輸入值

2010-02-05 13:44:06

C++ eof()函數(shù)

2010-01-04 14:14:43

Silverlight

2009-12-30 10:15:57

Silverlight

2009-12-30 16:19:49

Silverlight

2009-12-10 17:27:39

PHP操作Cookie

2010-02-22 17:58:06

WCF異步上傳

2009-12-15 10:23:23

Ruby應(yīng)用技巧
點(diǎn)贊
收藏

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