locked
Stopping image to get out of the screen while dragging in windows store app c# RRS feed

  • Question

  • Hello,

    Is there any way to stop image from getting out of the screen while dragging .

    I am using manipulationmode="TranslateInertia" and on manipulation delta here is the code:

     Windows.UI.Xaml.Controls.Grid gd= sender as Windows.UI.Xaml.Controls.Grid;
                var rt = gd.GetValue(RenderTransformProperty);
                var tt = rt as TranslateTransform;
                Windows.Foundation.Point p = e.Position;
    
                tt.X += e.Delta.Translation.X;
                tt.Y += e.Delta.Translation.Y;
                e.Handled = true;





    • Edited by zee_patel Wednesday, January 29, 2014 10:36 AM
    Wednesday, January 29, 2014 10:35 AM

Answers

  • You control how and where the image renders by how you set the translation tt. You can limit this by checking the values of tt and restricting them to the area you want. You will need to do some math to determine the valid coordinates based on the screen size, the image size, and the image position, then limit tt to those coordinates.

    --Rob

    • Marked as answer by zee_patel Thursday, January 30, 2014 7:03 AM
    Wednesday, January 29, 2014 2:40 PM
    Moderator

All replies

  • You control how and where the image renders by how you set the translation tt. You can limit this by checking the values of tt and restricting them to the area you want. You will need to do some math to determine the valid coordinates based on the screen size, the image size, and the image position, then limit tt to those coordinates.

    --Rob

    • Marked as answer by zee_patel Thursday, January 30, 2014 7:03 AM
    Wednesday, January 29, 2014 2:40 PM
    Moderator
  • Hi  Rob,

    Thanks for your reply...I was doing the same thing but as the rendering was too fast It was difficult to limit it with condition, finally I  decelerate its speed  and with added tweaks it's working perfectly now.

    Thursday, January 30, 2014 7:03 AM