Page view counter
mouse drag & drop logic
Last post 10-13-2008 3:26 PM by neal.gabriel. 3 replies.
Sort Posts:
10-10-2008 9:09 AM
mouse drag & drop logic

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

TPS2008

Loading...
Joined on 10-10-2008
Posts 14
10-11-2008 6:30 AM
Re: mouse drag & drop logic

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;
}

Mark as answer if this post answered your question.

Harsh Bardhan

HarshBardhan

Loading...
Joined on 05-07-2008
Bangalore
Posts 1,161
10-12-2008 10:41 AM
Re: mouse drag & drop logic

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 


http://kenwatts.blogspot.com/


Please select "Mark as Answer" for posts that are helpful. Thanks!

kwatts

Loading...
Joined on 08-18-2008
Belchertown, MA
Posts 436
10-13-2008 3:26 PM
Marked as Answer
Re: mouse drag &amp; drop logic

Try This

public Boolean IsMouseCaptured=false;

double beginX;

double beginY;

private void RectTitle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

{

this.RectTitle.CaptureMouse();

beginX = e.GetPosition(this.RectTitle).X;

beginY = e.GetPosition(this.RectTitle).Y;IsMouseCaptured = true;

}

private void RectTitle_MouseMove(object sender, MouseEventArgs e)

{

if (IsMouseCaptured)

{

this.RectTitleTransform.X = e.GetPosition(this).X - beginX;

this.RectTitleTransform.Y = e.GetPosition(this).Y - beginY;

}

}

private void RectTitle_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

{

this.RectTitle.ReleaseMouseCapture();

IsMouseCaptured = false;

}

HTH

Neal Gabriel

HTH
Neal Gabriel

neal.gabriel

Loading...
Joined on 07-18-2008
Cochin, India
Posts 13
Microsoft Communities