掃二維碼與項(xiàng)目經(jīng)理溝通
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢(xún)/運(yùn)營(yíng)咨詢(xún)/技術(shù)建議/互聯(lián)網(wǎng)交流
Silverlight拖拽功能的實(shí)現(xiàn)再實(shí)際開(kāi)發(fā)編程中是一個(gè)非常重要的基礎(chǔ)功能。對(duì)于一個(gè)開(kāi)發(fā)人員來(lái)說(shuō),如果想要很好的使用Silverlight來(lái)實(shí)現(xiàn)相關(guān)功能需求,就需要牢固掌握這些基礎(chǔ)功能的應(yīng)用。#t#

網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)公司!專(zhuān)注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、重慶小程序開(kāi)發(fā)公司、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶(hù)創(chuàng)新互聯(lián)還提供了舟曲免費(fèi)建站歡迎大家使用!
下面的示例演示如何在基于 Silverlight 的應(yīng)用程序中拖放對(duì)象。出于安全考慮,不能在應(yīng)用程序之間拖放對(duì)象。因此,說(shuō)成在 Silverlight 插件區(qū)域內(nèi)"滑動(dòng)"對(duì)象更為準(zhǔn)確。但是,術(shù)語(yǔ)"拖放"更為人知,因此在此處使用。
Silverlight拖拽功能Xaml腳本:
后置代碼:
- // Global variables used to
keep track of the- // mouse position and whether
the object is captured- // by the mouse.
- bool isMouseCaptured;
- double mouseVerticalPosition;
- double mouseHorizontalPosition;
- public void Handle_MouseDown
(object sender, MouseEventArgs args)- {
- Rectangle item = sender as Rectangle;
- mouseVerticalPosition = args.
GetPosition(null).Y;- mouseHorizontalPosition =
args.GetPosition(null).X;- isMouseCaptured = true;
- item.CaptureMouse();
- }
- public void Handle_MouseMove
(object sender, MouseEventArgs args)- {
- Rectangle item = sender as Rectangle;
- if (isMouseCaptured)
- {
- // Calculate the current
position of the object.- double deltaV = args.GetPosition(null).
Y - mouseVerticalPosition;- double deltaH = args.GetPosition(null).
X - mouseHorizontalPosition;- double newTop = deltaV + (double)
item.GetValue(Canvas.TopProperty);- double newLeft = deltaH + (double)
item.GetValue(Canvas.LeftProperty);- // Set new position of object.
- item.SetValue(Canvas.TopProperty, newTop);
- item.SetValue(Canvas.LeftProperty, newLeft);
- // Update position global variables.
- mouseVerticalPosition = args.
GetPosition(null).Y;- mouseHorizontalPosition = args.
GetPosition(null).X;- }
- }
- public void Handle_MouseUp(object
sender, MouseEventArgs args)- {
- Rectangle item = sender as Rectangle;
- isMouseCaptured = false;
- item.ReleaseMouseCapture();
- mouseVerticalPosition = -1;
- mouseHorizontalPosition = -1;
- }
Silverlight拖拽功能的實(shí)現(xiàn)方法就為大家介紹到這里啦。

我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢(xún)/運(yùn)營(yíng)咨詢(xún)/技術(shù)建議/互聯(lián)網(wǎng)交流