Ejemplo n.º 1
0
 void dragElement_Moved()
 {
     if (mIsDrag)
     {
         if (mContainer != null && mDragObject != null)
         {
             IDragElement     dragElement      = mDragObject as IDragElement;
             FrameworkElement frameworkElement = mDragObject as FrameworkElement;
             if (dragElement != null && frameworkElement != null)
             {
                 Point           point = Mouse.GetPosition(mContainer);
                 MatrixTransform mt    = frameworkElement.RenderTransform as MatrixTransform;
                 if (mt != null)
                 {
                     Matrix mx = mt.Matrix;
                     mx.OffsetX += point.X - mOriPosition.X;
                     mx.OffsetY += point.Y - mOriPosition.Y;
                     frameworkElement.RenderTransform = new MatrixTransform {
                         Matrix = mx
                     };
                     mOriPosition = point;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 void dragElement_MoveStarted()
 {
     if (mContainer != null && mDragObject != null)
     {
         IDragElement     dragElement      = mDragObject as IDragElement;
         FrameworkElement frameworkElement = mDragObject as FrameworkElement;
         if (dragElement != null && frameworkElement != null)
         {
             mOriPosition = Mouse.GetPosition(mContainer);
             mIsDrag      = true;
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 初始化容器和被拖动的元素
        /// </summary>
        /// <typeparam name="T">被拖动元素的类型,此类必须实现IDragElement接口</typeparam>
        /// <param name="container">容器</param>
        /// <param name="dragObject">拖动对象</param>
        public void Init <T>(IInputElement container, T dragObject) where T : FrameworkElement, IDragElement
        {
            mContainer  = container;
            mDragObject = dragObject;
            IDragElement dragElement = mDragObject as IDragElement;

            if (dragElement != null)
            {
                dragElement.MoveStarted += dragElement_MoveStarted;
                dragElement.MoveStopped += dragElement_MoveStopped;
                dragElement.Moved       += dragElement_Moved;
            }
            mOrgPoint = new Point(0, 0);
            mIsDrag   = false;
        }
Ejemplo n.º 4
0
 public DragElement(IDragElement element, IDragElement container) : this(new [] { element }, container)
 {
 }
Ejemplo n.º 5
0
 public DragElement(IEnumerable <IDragElement> elements, IDragElement container)
 {
     _elements  = elements.ToArray();
     _container = container as IContainer;
 }