[WPF] summarizes some of the drag and drop method for implementing (Window, UserControl)

Original: summary [WPF] Some implementations of drag (Window, UserControl)

Original Address https://www.cnblogs.com/younShieh/p/10811456.html

preamble

  • Follow this article the author only learn to master the general question of sort of drag and discussion, including the contents of windows, controls such as drag.
  • I hope this will find a solution to this problem for some people and some of the people some help just getting started, you can get the criticism is extremely honored. There are better ways, take the trouble to share with me, be grateful.
  • Various other implementations of this blog also are involved, many articles informative, there are pictures of code, I will not repeat the wheel made. To write some of their own understanding of it.

Key words

Window, UserControls, Drag


Reference material

http://www.cnblogs.com/DebugLZQ/archive/2013/05/07/3062733.html

Introduction This article is very comprehensive, covering all drag method. Reference worth learning.


text

1. Drag the window

We know that the mouse on the title bar of the window you can drag a form Press. We want to achieve by pressing the left mouse button and drag to achieve a particular place or places in all windows.

[Recommended] use DragMove () method, can be fully qualified.

  Reference: http://www.cnblogs.com/DebugLZQ/archive/2013/05/07/3062733.html

    ---Dividing line---

  other:

  1. Customize the title bar, use WindowChrome

  Suitable for borderless custom form and do not want to go to achieve full-screen, double-click, right-click menu of the title bar of the situation. Compare the situation referred to bother. (Personal feeling to use the feeling is not very good controllability, or their redesigned comfortable. ヽ (ー _ have) Techno

  2. Use drag the window to achieve SendMessage

  Apply. . . I was not very clear, did not ye used ( `· ω · '). The principle is to achieve mobile by sending a mobile command API User32 contained in the window. Learn from him.

  Reference: https://www.cnblogs.com/zhouyinhui/archive/2009/08/28/1555870.html

  A way to share interoperability wiki , can be found all use the Windows API, used when the check is very convenient. Baidu blind Gill said there may be a wrong answer. .


2. drag controls

[Recommended] use Blend in behavior to achieve drag

  VS Blend provides a powerful drag behavior realization of (behavior), do not have to go to complete the calculation and realization, extremely easy to use, truly "tap to play a year," it is very suitable for my kind of lazy.

  Reference: https://www.cnblogs.com/YGYH/archive/2010/09/10/1822724.html

  Problem: This drag acts, while easy to use, but applies only to drag child controls in the parent container.

    ---Dividing line---

  other:

  1. RenderTransform, TranslateTransform implemented properties

Translating (moving) objects in a two-dimensional coordinate system xy.

  RenderTransform property can be achieved interface conversion, rotation, scaling, skew, flip, and other functions. So we just need to get the value change when dragging, you can control the position of the various conversion.

  Reference: https://blog.csdn.net/qq_18995513/article/details/72765269#

  2. 【推荐】Thumb控件

表示可由用户拖动的控件。

  依赖于父容器进行使用,可以通过控件拖动时的属性值就能获取控件的垂直变化量和水平变化量。拖动DeltaEventArgs类在使用时,可以将按钮、图片等需要实现拖拽的内容放到Thumb下,通过拖拽Thumb来实现内容物的拖拽。参考学习这篇博文的2.1项

  3. Canvas容器中的子控件,通过点击下时记录的点,然后计算移动时的点的变化量,来重新计算子控件与父容器的相对位置。
参考学习这篇博文的2.3项

  4. Grid容器中的子控件拖拽的实现方法与Canvas大同小异,参考学习这篇博文的2.4项


后文

  以上应该就是在WPF中的各种拖拽的实现方法了,有简单的,也有复杂的。具体使用哪个,应该还是要根据使用需求来用。不过常用的就那几个(逃~

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/11300686.html