• <small id='eAowa'></small><noframes id='eAowa'>

        <bdo id='eAowa'></bdo><ul id='eAowa'></ul>

      <i id='eAowa'><tr id='eAowa'><dt id='eAowa'><q id='eAowa'><span id='eAowa'><b id='eAowa'><form id='eAowa'><ins id='eAowa'></ins><ul id='eAowa'></ul><sub id='eAowa'></sub></form><legend id='eAowa'></legend><bdo id='eAowa'><pre id='eAowa'><center id='eAowa'></center></pre></bdo></b><th id='eAowa'></th></span></q></dt></tr></i><div id='eAowa'><tfoot id='eAowa'></tfoot><dl id='eAowa'><fieldset id='eAowa'></fieldset></dl></div>

      1. <legend id='eAowa'><style id='eAowa'><dir id='eAowa'><q id='eAowa'></q></dir></style></legend><tfoot id='eAowa'></tfoot>
      2. Windows Phone 8.1 中 UIElement 的拖放延迟

        时间:2023-08-25

        1. <tfoot id='Osxfk'></tfoot>

            <tbody id='Osxfk'></tbody>
          1. <legend id='Osxfk'><style id='Osxfk'><dir id='Osxfk'><q id='Osxfk'></q></dir></style></legend>

                <small id='Osxfk'></small><noframes id='Osxfk'>

                <i id='Osxfk'><tr id='Osxfk'><dt id='Osxfk'><q id='Osxfk'><span id='Osxfk'><b id='Osxfk'><form id='Osxfk'><ins id='Osxfk'></ins><ul id='Osxfk'></ul><sub id='Osxfk'></sub></form><legend id='Osxfk'></legend><bdo id='Osxfk'><pre id='Osxfk'><center id='Osxfk'></center></pre></bdo></b><th id='Osxfk'></th></span></q></dt></tr></i><div id='Osxfk'><tfoot id='Osxfk'></tfoot><dl id='Osxfk'><fieldset id='Osxfk'></fieldset></dl></div>
                  <bdo id='Osxfk'></bdo><ul id='Osxfk'></ul>
                  本文介绍了Windows Phone 8.1 中 UIElement 的拖放延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 ManipulationDelta 事件处理程序将一个简单的椭圆拖放到屏幕上的画布中.我正在使用在几个地方在线发布的标准方法.以下是我的事件处理程序中的代码:

                  I'm using the ManipulationDelta event handler to drag and drop a simple ellipse in a canvas across the screen. I'm using the standard approach posted online in several places. Following is the code in my event handler:

                  Ellipse dragableItem = sender as Ellipse;
                  TranslateTransform translateTransform = dragableItem.RenderTransform as TranslateTransform;
                  double newPosX = Canvas.GetLeft(dragableItem) + translateTransform.X + e.Delta.Translation.X;
                  double newPosY = Canvas.GetTop(dragableItem) + translateTransform.Y + e.Delta.Translation.Y;
                  
                  if (!isCanvasBoundary(newPosX, TestCanvas.ActualWidth - dragableItem.ActualWidth, 0))
                        translateTransform.X += e.Delta.Translation.X;
                  
                  if (!isCanvasBoundary(newPosY, TestCanvas.ActualHeight - dragableItem.ActualHeight, 0))
                        translateTransform.Y += e.Delta.Translation.Y;
                  

                  拖放操作工作正常,但在用户开始拖动到椭圆实际改变其位置之间存在大约 1 秒的延迟.我可以通过打印到调试器看到事件处理程序本身几乎立即完成执行,所以我猜它有一些事情可以为屏幕上的所有 UIElements 执行预编程的刷新率,从而导致这种延迟?

                  The drag and drop operation works fine, but there's a nasty delay of around 1 second between when the user begins dragging to when the ellipse actually changes its position. I can see by printing to the Debugger that the event handler itself finishes executing almost instantly, so I'm guessing it has something to do a pre-programmed refresh rate for all UIElements on the screen that's causing this delay?

                  这个问题有什么办法吗?

                  Is there anyway around this issue?

                  推荐答案

                  我前段时间遇到了同样的问题.我想延迟是决定手势是拖动还是点击.如果不意外拖动,很难触摸屏幕.

                  I had the same problem some time ago. I guess that the delay is to decide whether the gesture is drag or tap. It's hard to touch a screen without any accidental drag.

                  要消除这种滞后,您可以使用 PointerMovePointerPressed 事件.这是我的例子.你有两个椭圆的画布,可以毫不拖延地拖动.

                  To eliminate this lag, you can use PointerMove and PointerPressed events. Here's my example. You have canvas with two ellipses which can be dragged without any delay.

                  XAML

                  <Grid>
                      <Canvas x:Name="Board" PointerMoved="Canvas_PointerMoved" Background="Black">
                          <Ellipse Width="64" Height="64" Fill="Red"
                                   Canvas.Left="32" Canvas.Top="128" PointerPressed="Ellipse_PointerPressed"/>
                          <Ellipse Width="96" Height=" 96" Fill="Blue"
                                   Canvas.Left="128" Canvas.Top="16" PointerPressed="Ellipse_PointerPressed"/>
                      </Canvas>
                  </Grid>
                  

                  如您所见,我正在处理画布中的 PointerMoved 事件和椭圆中的 PointerPressed 事件.重要的是画布的背景不透明以处理触摸事件.

                  As you can see, I'm handling PointerMoved event in canvas and PointerPressed event in ellipses. It's important that the background of the canvas is not transparent to handle touch events.

                  C#

                  public sealed partial class MainPage : Page
                  {
                      UIElement draggedItem = null;
                      Point offset;
                  
                      public MainPage()
                      {
                          this.InitializeComponent();
                          this.NavigationCacheMode = NavigationCacheMode.Required;
                      }
                  
                      private void Ellipse_PointerPressed(object sender, PointerRoutedEventArgs e)
                      {
                          draggedItem = sender as UIElement;
                          offset = e.GetCurrentPoint(draggedItem).Position;
                      }
                  
                      private void Canvas_PointerMoved(object sender, PointerRoutedEventArgs e)
                      {
                          if (draggedItem == null)
                              return;
                  
                          Point dragPoint = e.GetCurrentPoint(Board).Position;
                          Canvas.SetLeft(draggedItem, dragPoint.X - offset.X);
                          Canvas.SetTop(draggedItem, dragPoint.Y - offset.Y);
                      }
                  }
                  

                  我认为代码非常简单易懂.我使用 PointerPressed 来决定拖动哪个对象.我也在计算一些偏移量,因为我们想要相对于用户触摸的点移动对象.

                  I think the code is quite simple and understandable. I use PointerPressed to decide which object is dragged. I'm also calculating some offset, because we want to move the object relative to the point where user touches.

                  这篇关于Windows Phone 8.1 中 UIElement 的拖放延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何拖动&amp;将项目放在同一个 ListView 中? 下一篇:C# 将一个图片框拖放到另一个图片框

                  相关文章

                  最新文章

                      <bdo id='3vu9S'></bdo><ul id='3vu9S'></ul>
                    <tfoot id='3vu9S'></tfoot>
                    <i id='3vu9S'><tr id='3vu9S'><dt id='3vu9S'><q id='3vu9S'><span id='3vu9S'><b id='3vu9S'><form id='3vu9S'><ins id='3vu9S'></ins><ul id='3vu9S'></ul><sub id='3vu9S'></sub></form><legend id='3vu9S'></legend><bdo id='3vu9S'><pre id='3vu9S'><center id='3vu9S'></center></pre></bdo></b><th id='3vu9S'></th></span></q></dt></tr></i><div id='3vu9S'><tfoot id='3vu9S'></tfoot><dl id='3vu9S'><fieldset id='3vu9S'></fieldset></dl></div>
                    1. <small id='3vu9S'></small><noframes id='3vu9S'>

                    2. <legend id='3vu9S'><style id='3vu9S'><dir id='3vu9S'><q id='3vu9S'></q></dir></style></legend>