Skip to main content

Microsoft Silverlight

Answered Question mouse drag & drop logicRSS Feed

(0)

TPS2008
TPS2008

Member

Member

14 points

15 Posts

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

HarshBardhan
HarshBar...

Star

Star

9908 points

1,719 Posts

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

kwatts
kwatts

Contributor

Contributor

2129 points

436 Posts

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!

neal.gabriel
neal.gab...

Participant

Participant

789 points

161 Posts

Answered Question

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

Regards...

Neal Gabriel
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities