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

SilverLight拖動(dòng)具體實(shí)現(xiàn)方式介紹

開發(fā) 開發(fā)工具
SilverLight拖動(dòng)的代碼示例將會(huì)在文章為大家呈現(xiàn)出來。希望初學(xué)者們可以通過這些代碼示例清晰的解讀相關(guān)概念,以達(dá)到自己學(xué)習(xí)的目的。

SilverLight的使用可以幫助開發(fā)人員輕松的解決一些以前愛只能依靠美工才能解決的相關(guān)開發(fā)問題。現(xiàn)在我們將會(huì)學(xué)到其中的一個(gè)使用技巧,就是SilverLight拖動(dòng)的實(shí)現(xiàn)方式。#t#

SilverLight拖動(dòng)前臺(tái)代碼:

 

 

  1. < UserControl 
  2. xmlns="http://schemas.microsoft.
    com/winfx/2006/xaml/presentation"
     
  3. xmlns:x="http://schemas.
    microsoft.com/winfx/2006/xaml"
     
  4. x:Class="SilverlightApplic
    ation6.Page"
     
  5. Width="640" Height="480"> 
  6. < Canvas x:Name="LayoutRoot" 
    Background="White"> 
  7. < Image Margin="263,185,249,167" 
    Source="1.png" Stretch="Fill" 
    MouseLeftButtonDown="Image_
    MouseLeftButtonDown"
       
  8. MouseMove="Image_MouseMove" 
  9. MouseLeftButtonUp="Image_
    MouseLeftButtonUp"
    /> 
  10. < /Canvas> 
  11. < /UserControl> 

 

 

SilverLight拖動(dòng)后臺(tái)代碼:

 

 

  1. using System;  
  2. using System.Windows;  
  3. using System.Windows.Controls;  
  4. using System.Windows.Documents;  
  5. using System.Windows.Ink;  
  6. using System.Windows.Input;  
  7. using System.Windows.Media;  
  8. using System.Windows.Media.Animation;  
  9. using System.Windows.Shapes;  
  10. namespace SilverlightApplication6  
  11. {  
  12. public partial class Page : UserControl  
  13. {  
  14. bool trackingMouseMove = false;  
  15. Point mousePosition;  
  16. public Page()  
  17. {  
  18. // 需要初始化變量  
  19. InitializeComponent();  
  20. }  
  21. private void Image_MouseLeftButtonDown
    (object sender, MouseButtonEventArgs e)  
  22. {  
  23. FrameworkElement element = 
    sender as FrameworkElement;  
  24. mousePosition = e.GetPosition(null);  
  25. trackingMouseMove = true;  
  26. if (null != element)  
  27. {  
  28. element.CaptureMouse();  
  29. element.Cursor = Cursors.Hand;  
  30. }  
  31. }  
  32. private void Image_MouseMove(object 
    sender, MouseEventArgs e)  
  33. {  
  34. FrameworkElement element = sender 
    as FrameworkElement;  
  35. if (trackingMouseMove)  
  36. {  
  37. double deltaV = e.GetPosition(null).
    Y - mousePosition.Y;  
  38. double deltaH = e.GetPosition(null).
    X - mousePosition.X;  
  39. double newTop = deltaV + (double)element.
    GetValue(Canvas.TopProperty);  
  40. double newLeft = deltaH + (double)
    element.GetValue(Canvas.LeftProperty);  
  41. element.SetValue(Canvas.TopProperty, newTop);  
  42. element.SetValue(Canvas.LeftProperty, newLeft);  
  43. mousePosition = e.GetPosition(null);  
  44. }  
  45. }  
  46. private void Image_MouseLeftButtonUp
    (object sender, MouseButtonEventArgs e)  
  47. {  
  48. FrameworkElement element = sender 
    as FrameworkElement;  
  49. trackingMouseMove = false;  
  50. element.ReleaseMouseCapture();  
  51. mousePositionmousePosition.X = 
    mousePosition
    .Y = 0;  
  52. element.Cursor = null;  
  53. }  
  54. }  

 

以上就是對(duì)SilverLight拖動(dòng)相關(guān)實(shí)現(xiàn)方法做得具體介紹。

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

2010-01-04 16:06:34

Silverlight

2009-12-29 18:34:21

Silverlight

2009-12-15 13:47:33

Silverlight

2009-12-31 17:21:41

Silverlight

2009-12-31 15:05:00

Silverlight

2009-12-31 14:12:40

Silverlight

2009-12-30 17:19:09

Silverlight

2009-12-28 13:23:19

WPF導(dǎo)出圖片

2009-12-30 16:10:10

Silverlight

2009-12-30 16:43:47

Silverlight

2010-01-04 13:09:51

Silverlight

2010-01-04 16:30:06

Silverlight

2009-09-07 13:25:56

Silverlight

2009-12-30 17:44:22

Silverlight

2009-11-27 13:14:07

PHP函數(shù)strist

2010-06-11 16:19:23

vmware安裝ope

2009-12-30 14:36:29

Silverlight

2009-12-31 17:31:23

Silverlight

2009-12-30 15:08:04

Silverlight

2010-02-22 15:13:04

WCF分布式事務(wù)
點(diǎn)贊
收藏

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