Dragging an element within a certain region RRS feed

  • Question

  • For my Windows Store App in C#, I want to be able to drag an element/control within a certain region of the page. 

    For example, if you drag said item/element/image etc. outside a specific area I want it to be able to drag itself back into the accepted region or just not be able to leave the region at all.

    How would I go about implementing such a feature?

    Thursday, August 8, 2013 10:23 PM

All replies

  • You can handle manipulation (or pointer) events to update element's TranslationTransform and limit the new location to your specific area.  Take a look at the Quickstart: Touch input page for an example.

    Responding to user interaction is the category root for input.


    Thursday, August 8, 2013 11:28 PM
  • I've used the example to drag across the screen, but how would I use the manipulation events and TranslateTransform to the limit the location?
    Friday, August 9, 2013 10:20 AM
  • When you set the TranslateTransform you can clip the coordinates passed in to the manipulation events so that the element doesn't leave the area you want to limit it to.


    Saturday, August 10, 2013 1:10 AM
  • void Drag_ManipulationDelta(object sender, 
                ManipulationDeltaRoutedEventArgs e)
                if (dragTranslation.X <= 570)
                    dragTranslation.X += e.Delta.Translation.X;
                    dragTranslation.Y += e.Delta.Translation.Y;
    This is what I have, but doesn't seem to work. Have I used the correct manipulation event? (dragTranslation is an instance of TranslateTransform)
    Saturday, August 10, 2013 10:41 AM