自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何正確實(shí)現(xiàn)Silverlight拖拽功能

開發(fā) 開發(fā)工具
Silverlight拖拽功能的實(shí)現(xiàn)方法是一個(gè)比較復(fù)雜的過程。在這篇文章中,初學(xué)者可以通過一段代碼范例來具體的解讀這一技巧。

Silverlight拖拽功能的實(shí)現(xiàn)再實(shí)際開發(fā)編程中是一個(gè)非常重要的基礎(chǔ)功能。對(duì)于一個(gè)開發(fā)人員來說,如果想要很好的使用Silverlight來實(shí)現(xiàn)相關(guān)功能需求,就需要牢固掌握這些基礎(chǔ)功能的應(yīng)用。#t#

下面的示例演示如何在基于 Silverlight 的應(yīng)用程序中拖放對(duì)象。出于安全考慮,不能在應(yīng)用程序之間拖放對(duì)象。因此,說成在 Silverlight 插件區(qū)域內(nèi)"滑動(dòng)"對(duì)象更為準(zhǔn)確。但是,術(shù)語"拖放"更為人知,因此在此處使用。

Silverlight拖拽功能Xaml腳本:

 

  1. < UserControl x:Class=
    "DragAndDropSimple.Page" 
  2. xmlns="http://schemas.microsoft.
    com/winfx/2006/xaml/presentation"
       
  3. xmlns:x="http://schemas.
    microsoft.com/winfx/2006/xaml"
       
  4. Width="400" Height="300"> 
  5. < Canvas x:Name="rootCanvas" 
  6. Width="640" 
  7. Height="480" 
  8. Background="Gray" 
  9. > 
  10. < !-- You can drag this 
    rectangle around the canvas. --
    > 
  11. < Rectangle 
  12. MouseLeftButtonDown=
    "Handle_MouseDown" 
  13. MouseMove="Handle_MouseMove" 
  14. MouseLeftButtonUp="Handle_MouseUp" 
  15. Canvas.Left="30" Canvas.
    Top
    ="30" Fill="Red" 
  16. Width="50" Height="50" /> 
  17. < /Canvas> 
  18. < /UserControl> 

 

后置代碼:

 

  1. // Global variables used to 
    keep track of the   
  2. // mouse position and whether 
    the object is captured  
  3. // by the mouse.  
  4. bool isMouseCaptured;  
  5. double mouseVerticalPosition;  
  6. double mouseHorizontalPosition;  
  7. public void Handle_MouseDown 
    (object sender, MouseEventArgs args)   
  8. {  
  9. Rectangle item = sender as Rectangle;  
  10. mouseVerticalPosition = args.
    GetPosition(null).Y;  
  11. mouseHorizontalPosition = 
    args.GetPosition(null).X;  
  12. isMouseCaptured = true;  
  13. item.CaptureMouse();  
  14. }  
  15. public void Handle_MouseMove
    (object sender, MouseEventArgs args)   
  16. {  
  17. Rectangle item = sender as Rectangle;  
  18. if (isMouseCaptured)   
  19. {  
  20. // Calculate the current 
    position of the object.  
  21. double deltaV = args.GetPosition(null).
    Y - mouseVerticalPosition;  
  22. double deltaH = args.GetPosition(null).
    X - mouseHorizontalPosition;  
  23. double newTop = deltaV + (double)
    item.GetValue(Canvas.TopProperty);  
  24. double newLeft = deltaH + (double)
    item.GetValue(Canvas.LeftProperty);  
  25. // Set new position of object.  
  26. item.SetValue(Canvas.TopProperty, newTop);  
  27. item.SetValue(Canvas.LeftProperty, newLeft);  
  28. // Update position global variables.  
  29. mouseVerticalPosition = args.
    GetPosition(null).Y;  
  30. mouseHorizontalPosition = args.
    GetPosition(null).X;  
  31. }  
  32. }  
  33. public void Handle_MouseUp(object 
    sender, MouseEventArgs args)   
  34. {  
  35. Rectangle item = sender as Rectangle;  
  36. isMouseCaptured = false;  
  37. item.ReleaseMouseCapture();  
  38. mouseVerticalPosition = -1;  
  39. mouseHorizontalPosition = -1;  

 

Silverlight拖拽功能的實(shí)現(xiàn)方法就為大家介紹到這里啦。

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

2009-12-03 11:11:57

PHP網(wǎng)站優(yōu)化

2010-02-25 10:10:29

WCF使用Header

2009-12-04 12:51:27

PHP functio

2009-12-11 17:52:21

PHP獲取博客數(shù)據(jù)

2009-12-07 18:42:55

PHP與Javascr

2010-01-06 15:56:18

.Net Framew

2009-12-09 16:49:09

PHP顯示文章發(fā)布時(shí)間

2009-12-08 14:31:31

PHP命令行讀取參數(shù)

2009-12-15 14:09:39

Ruby創(chuàng)建可參數(shù)化類

2010-01-15 16:03:48

VB.NET重載Win

2010-02-24 10:07:48

WCF跨越邊界

2010-03-04 15:12:33

Python算法

2010-03-04 11:12:02

Python AOP

2010-04-29 17:31:56

Oracle存儲(chǔ)過程

2019-05-07 10:21:48

人工智能AI

2009-12-08 19:29:10

PHP生成唯一標(biāo)識(shí)符

2009-11-25 16:36:29

PHP刪除數(shù)組重復(fù)元素

2010-08-05 14:03:46

連接ibm DB2

2020-10-15 10:51:05

云計(jì)算IT技術(shù)

2009-12-21 10:09:26

WCF創(chuàng)建客戶端服務(wù)對(duì)
點(diǎn)贊
收藏

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