日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

兼容Silverlight4的实用的Silverlight可拖放工具类源代码

發(fā)布時(shí)間:2023/11/27 生活经验 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 兼容Silverlight4的实用的Silverlight可拖放工具类源代码 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

開發(fā)日常的Silverlight應(yīng)用程序時(shí),常常要對一個域多個控件實(shí)現(xiàn)可拖放的MOUSE操作,在Silverlight中實(shí)現(xiàn)拖放的功能其實(shí)非常簡單,但是為了提高程序功能代碼的可復(fù)用性,程序員常常喜歡把常用的代碼封裝成一個工具類,例如Asp.net中常用SQLHelper類,用來操作數(shù)據(jù)庫的,這里我們介紹的類是在Silverlight中實(shí)現(xiàn)拖動的工具類,它支持Silverlight2.0至Silverlight4.0的各個版本通用,好了話不多說,我們還是看代碼吧:

public static class DragDrop
{private static bool IsDragging = false;private static Point curPoint;private const int MAX_ZINDEX = 99999;private const double CURRENT_OPACITY = 0.5;private static int lastZIndex;private static double lastOpacity;private static void sender_MouseLeftButtonDown(object sender, MouseButtonEventArgs e){UIElement uiElement = sender as UIElement;if (uiElement != null){uiElement.CaptureMouse();lastZIndex = (int)uiElement.GetValue(Canvas.ZIndexProperty);uiElement.SetValue(Canvas.ZIndexProperty, MAX_ZINDEX);lastOpacity = uiElement.Opacity;uiElement.Opacity = CURRENT_OPACITY;IsDragging = true;curPoint = new Point(e.GetPosition(null).X, e.GetPosition(null).Y);}}private static void sender_MouseMove(object sender, MouseEventArgs e){if (!IsDragging){return;}UIElement uiElement = sender as UIElement;if (uiElement != null){double currentLeft = (double)uiElement.GetValue(Canvas.LeftProperty);double currentTop = (double)uiElement.GetValue(Canvas.TopProperty);double newLeft = (double)currentLeft + e.GetPosition(null).X - curPoint.X;double newTop = (double)currentTop + e.GetPosition(null).Y - curPoint.Y;uiElement.SetValue(Canvas.LeftProperty, newLeft);uiElement.SetValue(Canvas.TopProperty, newTop);curPoint = new Point(e.GetPosition(null).X, e.GetPosition(null).Y);}}private static void sender_MouseLeftButtonUp(object sender, MouseButtonEventArgs e){UIElement uiElement = sender as UIElement;if (uiElement != null){uiElement.ReleaseMouseCapture();IsDragging = false;uiElement.SetValue(Canvas.ZIndexProperty, lastZIndex);uiElement.Opacity = lastOpacity;}}public static void Load(UIElement sender){sender.MouseLeftButtonDown += new MouseButtonEventHandler(sender_MouseLeftButtonDown);sender.MouseLeftButtonUp += new MouseButtonEventHandler(sender_MouseLeftButtonUp);sender.MouseMove += new MouseEventHandler(sender_MouseMove);}public static void UnLoad(UIElement sender){sender.MouseLeftButtonDown -= new MouseButtonEventHandler(sender_MouseLeftButtonDown);sender.MouseLeftButtonUp -= new MouseButtonEventHandler(sender_MouseLeftButtonUp);sender.MouseMove -= new MouseEventHandler(sender_MouseMove);}
}DragDrop工具類的使用方法:
DragDrop.Load(LayoutRoot);
DragDrop是一個靜態(tài)類,使用起來非常簡單,以上只要一行代碼就可以實(shí)現(xiàn)對Grid控件的拖放操作了。
希望對大家有所幫助~!

轉(zhuǎn)載于:https://www.cnblogs.com/slteam/archive/2010/03/18/1689384.html

總結(jié)

以上是生活随笔為你收集整理的兼容Silverlight4的实用的Silverlight可拖放工具类源代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。