【问题标题】:wpf touch desktop app in windows 8Windows 8中的wpf触摸桌面应用程序
【发布时间】:2014-02-20 03:51:51
【问题描述】:

我有一个在 Windows 7 中编写的 wpf 应用程序,并且运行良好。我正在移植到 Windows 8.1,触摸事件的行为完全不同。

我编写了一个控件,当拖放到另一个相同类型的控件上时,它会切换位置。下面是控件的 previewTouchDown 和 Drop 处理程序。

private void UserControl_PreviewTouchDown(object sender, TouchEventArgs e)
    {
        DragDrop.DoDragDrop(this, _comparisonElement, DragDropEffects.Copy);
    }

private void UserControl_Drop(object sender, DragEventArgs e)
    {
        ComparisonCopy from = (ComparisonCopy)e.Data.GetData("comparisonFormat");
        ComparisonCopy to = (ComparisonCopy)_comparisonElement.GetData("comparisonFormat");

        if (from != to)
        {
            ComparisonEventArgs args = new ComparisonEventArgs();
            args.from = from;
            args.to = to;

            this.ComparisonMoved(sender, args);

            e.Handled = true;
        }
    }

在 Windows 8.1 中运行它会导致拖放工作一次。一旦它起作用,它将永远不会再次起作用。似乎初始拖放处于卡住状态。

我尝试使用允许多次切换的 DragMove 事件,但是,它会随机切换控件。只要我触摸屏幕上的另一个控件,它就会用那个控件替换最后一个控件。再次,似乎触摸被某种方式卡住了。

使用鼠标执行此操作 100% 的时间。

感谢您的帮助。 -马特

【问题讨论】:

    标签: c# wpf windows touch windows-8.1


    【解决方案1】:

    我在 Windows 8.1 中使用了这篇文章 Drag-and-Drop with Touch on Windows 7 中的代码示例,并且看到了类似的东西。

    在更改代码以处理 TouchMove 而不是 TouchDown 之前,Drop 事件根本不会触发。我最终得到的是以下内容:

    <StackPanel>
        <Label Content="StackOverflow" HorizontalAlignment="Center"
               TouchMove="Label_TouchMove" />
        <Label Content="Drag to here"
               HorizontalAlignment="Center"
               AllowDrop="True" Drop="Label_Drop" />
    </StackPanel>
    
    // Drag source
    private void Label_TouchMove(object sender, TouchEventArgs e)
    {
        Label l = e.Source as Label;
        DragDrop.DoDragDrop(l, l.Content + " was Dragged!", DragDropEffects.Copy);
    }
    
    // Drag target
    private void Label_Drop(object sender, DragEventArgs e)
    {
        string draggedText = (string)e.Data.GetData(DataFormats.StringFormat);
        Label l = e.Source as Label;
        l.Content = draggedText;
    }
    

    但是现在在拖动完成后会触发一个额外的 TouchMove。我找不到发生这种情况的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 2012-10-06
      • 1970-01-01
      • 2011-01-04
      • 2012-08-23
      • 1970-01-01
      相关资源
      最近更新 更多