Silverlight drag and drop reference code

Source: Internet
Author: User

Public Partial Class Page:Usercontrol

{ Bool Isdragdropineffect =False; Point Pos; Public Page () { Initializecomponent (); // Loop through all the uielements in the canvas // And attach mouse event handlers to the element Foreach(UielementUieleInCanvasparent. Children) { Uiele. mousemove + =New Mouseeventhandler(Element_mousemove ); Uiele. mouseleftbuttondown + =New Mousebuttoneventhandler(Element_mouseleftbuttondown ); Uiele. mouseleftbuttonup + =New Mousebuttoneventhandler(Element_mouseleftbuttonup ); } } Void Element_mousemove (ObjectSender,MouseeventargsE) { If(Isdragdropineffect) { FrameworkelementCurrele = senderAs Frameworkelement; // Retrieving the item's current X and Y position DoubleXpos = E. getposition (Null). X-pos. X; DoubleYpos = E. getposition (Null). Y-pos. Y; // Re-position Element Currele. setvalue (Canvas. Topproperty, ypos + (Double) Currele. getvalue (Canvas. Topproperty )); Currele. setvalue (Canvas. Leftproperty, xpos + (Double) Currele. getvalue (Canvas. Leftproperty )); // Reset the new position value Pos = E. getposition (Null); } } Void Element_mouseleftbuttondown (ObjectSender,MousebuttoneventargsE) { FrameworkelementFele = senderAs Frameworkelement; Isdragdropineffect =True; // X and Y coords of mouse pointer position Pos = E. getposition (Null); // Enable Mouse capture on Element Fele. capturemouse (); // Set the cursor to 'hand' when mouse pointer is over element Fele. cursor =Cursors. Hand; } Void Element_mouseleftbuttonup (ObjectSender,MousebuttoneventargsE) { If(Isdragdropineffect) { FrameworkelementEle = senderAs Frameworkelement; Isdragdropineffect =False; // Removes Mouse capture from element being dragged Ele. releasemousecapture (); } }

}

 

This sectionCodeChange all elements in canvascontent to drag-and-drop.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.