0

I'd like to make slide a ball on my screen following my finger. i get the cursor position but the ball is not following my finger qwhen i'm sliding. Moreover i have severals balls. (Not for the moment but i have planed to)

My Code :

c#

private void MouseMoving(object sender, MouseEventArgs e)
{
    if (sender.GetType() == typeof(Image))
    {                             
        System.Windows.Point cursorpos = e.GetPosition(null);
        Image realSender = (Image)sender;
        // MessageBox.Show(cursorpos.X.ToString());
        // MessageBox.Show(cursorpos.Y.ToString());
        Canvas.SetLeft(realSender, cursorpos.X);                   
        Canvas.SetTop(realSender, cursorpos.Y);
        Canvas.SetZIndex(realSender, idx++);
    }

}

XAML

<Image Name="image1" Stretch="Fill" Source="/bal.png" 
       MouseMove="MouseMoving" Grid.ColumnSpan="4" 
       Canvas.Left="337" Canvas.Top="239"/`>
iabbott
  • 873
  • 1
  • 8
  • 23
Gabson
  • 421
  • 1
  • 4
  • 20
  • Is this a question? [FAQ](http://stackoverflow.com/help/how-to-ask) –  Oct 10 '13 at 08:18
  • The question is not explicit, but what i 'm looking for is a method or a way to make the object follow my finger; i'm begginner as c# developer – Gabson Oct 10 '13 at 08:24
  • Maybe calling Canvas.UpdateLayout will help –  Oct 10 '13 at 08:28
  • The ball is always going on the same position, in the bottom and i dunno why. I have tried to invert cursorpos.x and cursorpos.y. – Gabson Oct 10 '13 at 08:35
  • Use e.X and e.Y. e.GetPosition(null) most propably return (0,0). –  Oct 10 '13 at 08:40
  • Visual saying there is no such method (e.Y or e.X) and getpostion return a "Point" object. What could replace the null value ? – Gabson Oct 10 '13 at 08:43
  • Ah sorry wrong namespace. Try e.GetPosition(this) to get the mouse position in your application or e.GetPosition(Canvas) to get the mouse position relative to you canvas. [MSDN](http://msdn.microsoft.com/en-us/library/system.windows.input.mouseeventargs.getposition.aspx) –  Oct 10 '13 at 09:00
  • both are working, but its jerky and i can only go on the bottom right. – Gabson Oct 10 '13 at 09:06
  • http://social.msdn.microsoft.com/Forums/wpapps/en-us/ef77935a-29db-4bcc-9e4a-3237cd55b470/how-to-move-an-object-based-on-a-dragging-gesture-using-manipulation-events-in-silverlight?forum=wphowto – Gabson Oct 10 '13 at 09:34
  • @Gabson make sure you set CacheMode="BitmapCache" on you Image to benefit from harware acceleration – Benoit Catherinet Oct 10 '13 at 15:28

0 Answers0