6

I have successfully set my Grid up for dragging with a mouse with

<Grid x:Name="SourceGrid13"
              CanDrag="True"
              DragStarting="SourceGrid_DragStarting"
              Margin="0,20,0,0">

However, this is not draggable on a Windows Phone (Windows 10) by touching. How do I set that up?

Also I assume once I get the Grid dragging, the drop sequence will be the same as with a mouse? This is my drop code:

 <ListView HorizontalAlignment="Center" AllowDrop="True"
                 Drop="Image_Drop"
                 DragEnter="TargetImage_DragEnter"
                 DragLeave="TargetImage_DragLeave"
                 CanDragItems="True"
                 IsSwipeEnabled="True"
                 MinHeight="124"
                 Grid.Row="4"
                 Grid.Column="1">
                <Image Height="224"/>
 </ListView>

Also on tablet, it is hard to, but it will drag by touch. Do I need to enable it on the phone somewhere?

I'm now thinking touch drag may be disabled until a future update or the actual release on Windows 10 on Windows Phone.

UPDATE Based on Answers:

I set my listView's CanDragItems and IsSwipeEnabled to True, but this did not change anything. I applied the manipulation rectangle with some strange results. On Phone, I am able to drag the rectangle, but when I bring it into my ListViews, it disappears. Shown by these pictures:

Full Rect:

enter image description here

Dragged it Down out of Framework element- It is dragged behind the listView.

enter image description here

On Desktop, The rectangle is dragged in front of the listView, but after being dragged out of the original Framework Element, it is undraggable.

enter image description here

Seth Kitchen
  • 1,526
  • 19
  • 53
  • Does it work on phone when you double tap the object? According the [this question](http://stackoverflow.com/questions/30918559/in-wpf-based-desktop-app-touch-drag-and-drop-is-working-on-window-7-but-not-on-w) "This might have to do w/ the OS settings of Windows 8. Look at "Pen and Touch" settings" – d.moncada – Bennett Yeo Nov 24 '15 at 16:00
  • @KiroYakuza Does not work if I double tap. There is no pen and touch setting (Maybe because Windows 10). When I search for pen nothing comes up. When I search for touch, there is a touch setting but it doesn't open. – Seth Kitchen Nov 24 '15 at 16:03
  • Did you tried this solution?http://stackoverflow.com/questions/3191084/wpf-4-multi-touch-drag-and-drop – ApceH Hypocrite Nov 25 '15 at 21:41
  • @ApceHHypocrite Is that available in Windows Universal? Can you post some code – Seth Kitchen Nov 25 '15 at 21:43
  • Seems that your questions concerns Windows 10 platform, therefore I've changed its tags to more apropriate ones. Please correct me if I'm wrong. – Romasz Nov 26 '15 at 18:16
  • I think you [should set CanDragItems to true](https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.uielement.allowdrop) in your *ListView*. Also it may be needed [to check IsSwipeEnabled](https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.listviewbase.candragitems.aspx) as mouse-touch behavior may be dependent on it. – Romasz Nov 26 '15 at 18:34
  • @Romasz I have set both to true to no avail – Seth Kitchen Nov 30 '15 at 17:28
  • I think there's 2 different patterns here - There is the drag and drop functionality (CanDragItems, AllowDrop etc) and there is using the render transform to move the physical position of something on the screen. Are you trying to drop something into another element to move them between each other (it sounds like you are) or are you trying to just move the location of an element on screen using touch? – Dan Harris Jul 13 '16 at 15:53

1 Answers1

7

All needed things for any touch screen manipulations are here from the box. There is simple example - Rectangle on the Canvas:

<Canvas Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Rectangle Width="50" Height="50" Fill="Blue" RenderTransformOrigin="0.5,0.5"
        ManipulationDelta="Rectangle_ManipulationDelta" ManipulationMode="All">
        <Rectangle.RenderTransform>
            <TranslateTransform x:Name="dragTranslation" />
        </Rectangle.RenderTransform>
    </Rectangle>
</Canvas>

A minimal handling code is:

private void Rectangle_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) {
    dragTranslation.X += e.Delta.Translation.X;
    dragTranslation.Y += e.Delta.Translation.Y;
}

It enough to drag any UIElement on Canvas on touch screens AND on desktop with mouse. Dragging of Grid also works.

ApceH Hypocrite
  • 1,093
  • 11
  • 28
  • I only had time to test it on Desktop, and it worked the first time I drag, but after I dropped it, I cannot pick it up again. It also doesn't go back to the same position after the drop – Seth Kitchen Nov 25 '15 at 22:57
  • I have edited my question with bugs related to your answer – Seth Kitchen Nov 30 '15 at 17:26