English 中文(简体)
WPF 远距门槛
原标题:WPF drag distance threshold

我有一个方案,有两部WPF树图,允许在两者之间ging积和 dropping落。 问题在于,它可能无意在树苗上开立/关闭项目,因为把 mo改成一只平子,同时保留左 mo子,会引发rag/ drop功能。 是否有办法说明在考虑rag/ drop之前, mo应走多少?

问题回答

这里有一个系统参数。 如果是,

Point down = {where mouse down event happened}
Point current = {position in the MouseMove eventargs}

那么,如果是这样的话,则该运动会缩短了最低限度的距离。

Math.Abs(current.X - down.X) >= SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(current.Y - down.Y) >= SystemParameters.MinimumVerticalDragDistance

仅仅在你确定拖延何时开始的法典中打上了一点缓冲。

  1. flag mouse down
  2. on mouse move - check for mouse down.. if yes, check to see if its moved farther than whatever buffer you specify (3 pixels is probably good)
  3. if it has, start the drag.

ts article for Drag and Drop implementation, 您将不得不处理2次 mo动事,以便拖延拖到 mo运动已经走了一定距离。 首先,增加一名手提车,储存与你控制有关的最初改变立场。 承诺使用MouseDown活动,因为这是一个泡沫活动,可能由儿童控制处理,然后才能获得你的控制。

public class DraggableControl : UserControl
{
  private Point? _initialMousePosition;

  public DraggableControl()
  {
    PreviewMouseDown += OnPreviewMouseDown;
  }

  private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e) {
    _initialMousePosition = e.GetPosition(this);
  }

此外,还处理使用 着手检查迁移距离,并最终启动拖拉行动:

  ...
  public DraggableControl()
  {
    ...
    MouseMove += OnMouseMove;
  }
  ...
  private void OnMouseMove(object sender, MouseEventArgs e)
  {
    // Calculate distance between inital and updated mouse position
    var movedDistance = (_initialMousePosition - e.GetPosition(this)).Length;
    if (movedDistance > yourThreshold)
    {
      DragDrop.DoDragDrop(...);
    }
  }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签