Skip to main content
Home Forums Silverlight Programming Programming with .NET - General mouse drag & drop logic
3 replies. Latest Post by neal.gabriel on October 13, 2008.
(0)
TPS2008
Member
14 points
15 Posts
10-10-2008 9:09 AM |
Hi
http://www.tiffany.com/charms/default.aspx?backlink=category
we are trying to design a similar application in silverlight; we can easily achive simple drag and drop function with mouse capture event; However how to implement the fucntionality where in the pendent auto places itself correctly at the preset place.
For example if you will drag and drop a pendent/charm near the chain it goes and auto latches itself to a particular point
Can someone help with the logic
Thanks
Prashant
HarshBar...
Star
9908 points
1,719 Posts
10-11-2008 6:30 AM |
Hi,
i am not having any such code but i can try by Pasting some Sample Hardcoded kind of stuff.
Hopefully you can create a logic from that.
Point newPoint=//Call RepositionImage method by passing appropriate values
YourObject.SetValue(Canvas.LeftProperty, newPoint.X); YourObject.SetValue(Canvas.TopProperty, newPoint.Y);
private Point RepositionImage(Point currentPoint, int imageWidth, int imageHeight ){ Point updatedPoint = new Point(); if (0 <= currentPoint.X && currentPoint.X <= 60) { updatedPoint.X = (60 - imageWidth) / 2; } else if (61 <= currentPoint.X && currentPoint.X <= 120) { updatedPoint.X = 60 + (60 - imageWidth) / 2; } else if (121 <= currentPoint.X && currentPoint.X <= 180) { updatedPoint.X = 120 + (60 - imageWidth) / 2; } //y if (0 <= currentPoint.Y && currentPoint.Y <= 60) { updatedPoint.Y = (60 - imageWidth) / 2; } else if (61 <= currentPoint.Y && currentPoint.Y <= 120) { updatedPoint.Y = 60 + (60 - imageWidth) / 2; } else if (121 <= currentPoint.Y && currentPoint.Y <= 180) { updatedPoint.Y = 120 + (60 - imageWidth) / 2; } return updatedPoint;}
kwatts
Contributor
2129 points
436 Posts
10-12-2008 10:41 AM |
Prashant,
Did you see my response on this thread:
http://silverlight.net/forums/t/35412.aspx
If so, did it help or do you need more guidance?
-Ken
neal.gab...
Participant
789 points
161 Posts
10-13-2008 3:26 PM |
Try This
public
{
beginX = e.GetPosition(
}
HTH
Neal Gabriel