c# - 如何在 Windows 10 Phone 的 Windows 通用应用程序中设置触摸拖动?

标签 c# windows-10 drag uwp windows-10-mobile

我已经成功地设置了我的网格,可以用鼠标拖动

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

但是,这在 Windows Phone (Windows 10) 上无法通过触摸拖动。我该如何设置?

我还假设一旦我拖动了 Grid,放置顺序将与鼠标相同?这是我的放置代码:

 <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>

同样在平板电脑上,很难,但它会通过触摸拖动。我需要在手机上的某个地方启用它吗?

我现在认为,在未来的更新或 Windows Phone 上的 Windows 10 实际发布之前,触摸拖动可能会被禁用。

根据答案更新:

我将 listView 的 CanDragItems 和 IsSwipeEnabled 设置为 True,但这并没有改变任何东西。我应用了一些奇怪的结果的操作矩形。在 Phone 上,我可以拖动矩形,但是当我将它放入我的 ListViews 时,它就消失了。这些图片显示:

完整矩形:

enter image description here

将其拖出 Framework 元素 - 它被拖到 listView 后面。

enter image description here

在Desktop上,矩形被拖到listView前面,但拖出原来的Framework Element后,就不可拖了。

enter image description here

最佳答案

所有触摸屏操作所需的东西都在盒子里。有一个简单的例子 - Canvas 上的 Rectangle:

<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>

一个最小的处理代码是:

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

它足以在触摸屏和桌面上使用鼠标将任何 UIElement 拖动到 Canvas 上。拖动 Grid 也有效。

关于c# - 如何在 Windows 10 Phone 的 Windows 通用应用程序中设置触摸拖动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33658737/

相关文章:

c# - 多列多对一

c# - 我们的自定义类数组如何在没有实现 IEnumerable 的情况下与 foreach 一起工作?

visual-studio-2015 - Visual Studio 2015 社区中缺少通用应用程序模板

c++ - 将窗口位置限制在桌面工作区

c# - 在没有转换器的情况下自定义 System.Text.Json 的序列化?

c# - MonoTouch 中的 UITableView 多选

python-3.x - xml.parsers.expat.ExpatError : not well-formed (invalid token)

python - Spark 安装 - 错误 : Could not find or load main class org. apache.spark.launcher.Main

C# Windows 窗体 : Drop a picture into a WPF RichTextBox (in ElementHost)

ios - 防止可拖动 View 离开屏幕