1

如何SurfaceWindow通过用手指拖动/捏合来移动/调整自身大小而不会出现异常行为?我有一个 Surface Window,已IsManipulationEnabled选中。在ManipulationStarting中,我有:

    e.ManipulationContainer = this; <--- source of unpredictable behavior?
    e.Handled = true;

ManipulationDelta

    this.Left += e.DeltaManipulation.Translation.X;
    this.Top += e.DeltaManipulation.Translation.Y;
    this.Width *= e.DeltaManipulation.Scale.X; <----zooming works properly
    this.Height *= e.DeltaManipulation.Scale.X;

    e.Handled = true;

移动的问题是它会在两个完全不同的位置之间不停地跳来跳去,给它一个闪烁的效果。我在控制台中打印了一些数据,似乎 e.ManipulationOrigin 一直在变化。以下数据是我在屏幕上拖动(仅打印 X 值)并在最后将手指静止一秒钟后的值:

Window.Left    e.Manipulation.Origin.X    e.DeltaManipulation.Translation.X
---------------------------------------------------------------------------
1184           699.616                    0
1184           577.147                    -122.468
1062           577.147                    0
1062           699.264                    122.117
1184           699.264                    0
1184           576.913                    -122.351

and it goes on 

您可以从中看到Window.Left它在 2 个位置之间跳跃。在我停止用手指移动窗户后,如何让它保持静止?

4

1 回答 1

0

下面的代码至少允许你拖动;它通过使用屏幕坐标解决了您遇到的问题 - 因为使用窗口坐标意味着参考点随着窗口的移动而变化。

有关更多信息,请参阅http://www.codeproject.com/Questions/671379/How-to-drag-window-with-finger-not-mouse

 static void MakeDragging(Window window) {
            bool isDown = false;
            Point position = default(Point);
            window.MouseDown += (sender, eventArgs) => {
                if (eventArgs.LeftButton != MouseButtonState.Pressed) return;
                isDown = true;
                position = window.PointToScreen(eventArgs.GetPosition(window));
            };
            window.MouseUp += (sender, eventArgs) => {
                if (eventArgs.LeftButton != MouseButtonState.Released) return;
                isDown = false;
            };
            window.MouseMove += (sender, eventArgs) => {
                if (!isDown) return;
                Point newPosition = window.PointToScreen(eventArgs.GetPosition(window));
                window.Left += newPosition.X - position.X;
                window.Top += newPosition.Y - position.Y;
                position = newPosition;
            };
        } //MakeDragging
于 2013-10-29T04:42:21.123 回答