Пример #1
1
        /* ____________________________________________________________________
         *		Drag Source events
         * ____________________________________________________________________
         */
        static void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Make this the new drag source
            _currentSourceAdvisor = GetDragSourceAdvisor(sender as DependencyObject);

            if (_currentSourceAdvisor.IsDraggable(e.Source as UIElement) == false) return;

            _draggedElt = e.Source as UIElement;
            _startPoint = e.GetPosition(GetTopContainer());
            _isMouseDown = true;
        }
Пример #2
0
			public DragInfo(IDragSourceAdvisor adv)
			{
				if (adv == null)
					throw new ArgumentNullException();

				SourceAdvisor = adv;
			}
Пример #3
0
            public DragInfo(IDragSourceAdvisor adv)
            {
                if (adv == null)
                {
                    throw new ArgumentNullException();
                }

                SourceAdvisor = adv;
            }
Пример #4
0
        static void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            IDragSourceAdvisor adv = GetDragSourceAdvisor(sender as UIElement);

            if (!adv.IsDraggable(e.Source as UIElement))
            {
                return;
            }

            DragSource = new DragInfo(adv);
            DragSource.DraggedElement = e.Source as UIElement;
            DragSource.StartPoint     = e.GetPosition(DragSource.DraggedElement);
            DragSource.IsMouseDown    = true;
        }
Пример #5
0
        private static void DragSourcePreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Make this the new drag source
            IDragSourceAdvisor advisor = GetDragSourceAdvisor(sender as DependencyObject);

            if (advisor.CanBeDragged(e.Source as UIElement) == false)
            {
                return;
            }

            s_DraggedElement = e.Source as UIElement;
            s_DragStartPoint = e.GetPosition(GetTopContainer());
            s_OffsetPoint    = e.GetPosition(s_DraggedElement);
            s_IsMouseDown    = true;
        }
Пример #6
0
        private static void DragStarted(UIElement uiElement)
        {
            s_IsMouseDown = false;
            Mouse.Capture(uiElement);

            IDragSourceAdvisor advisor          = GetDragSourceAdvisor(uiElement);
            DataObject         data             = advisor.GetDataObject(s_DraggedElement, s_OffsetPoint);
            DragDropEffects    supportedEffects = advisor.SupportedEffects;

            // Perform DragDrop
            DragDropEffects effects = DragDrop.DoDragDrop(s_DraggedElement, data, supportedEffects);

            advisor.FinishDrag(s_DraggedElement, effects);

            // Clean up
            RemovePreviewAdorner();
            Mouse.Capture(null);
            s_DraggedElement = null;
        }
Пример #7
0
        private static void OnDragSourceAdvisorChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs args)
        {
            UIElement sourceElt = depObj as UIElement;

            if (args.NewValue != null && args.OldValue == null)
            {
                sourceElt.PreviewMouseLeftButtonDown += DragSource_PreviewMouseLeftButtonDown;
                sourceElt.PreviewMouseMove           += DragSource_PreviewMouseMove;
                sourceElt.PreviewMouseUp             += DragSource_PreviewMouseUp;
                // Set the Drag source UI
                IDragSourceAdvisor advisor = args.NewValue as IDragSourceAdvisor;
                advisor.SourceUI = sourceElt;
            }
            else if (args.NewValue == null && args.OldValue != null)
            {
                sourceElt.PreviewMouseLeftButtonDown -= DragSource_PreviewMouseLeftButtonDown;
                sourceElt.PreviewMouseMove           -= DragSource_PreviewMouseMove;
                sourceElt.PreviewMouseUp             -= DragSource_PreviewMouseUp;
            }
        }
Пример #8
0
        /// <summary>
        /// Called when the left mouse button is pressed while the mouse pointer is over drag source element.
        /// </summary>
        /// <param name="sender">Drag source element.</param>
        /// <param name="e">Provides data for mouse button.</param>
        private static void DragSourcePreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Make this the new drag source
            currentSourceAdvisor = GetDragSourceAdvisor(sender as DependencyObject);

            // Todo: consider to pass FrameworkElement.DataContext directly instead if UIElement
            if (currentSourceAdvisor.IsDraggable(e.Source as UIElement) == false)
            {
                return;
            }

            dragElement = e.Source as UIElement;

            // Important: for global (i.e. "window root grid") adorner layer use local (to element) mouse position as start point.
            startPoint = e.GetPosition((UIElement)e.Source);

            // For local (to element) adorner layer use global mouse position as start point instead.
            //startPoint = e.GetPosition(GetTopContainer());

            isMouseDown = true;
        }
Пример #9
0
        static void DragStarted(object uiObject)
        {
            // prepare
            DragSource.IsMouseDown = false;
            Mouse.Capture(DragSource.DraggedElement);

            // gather data
            IDragSourceAdvisor adv              = GetDragSourceAdvisor(uiObject as UIElement);
            DataObject         data             = DragSource.SourceAdvisor.GetDataObject(DragSource.DraggedElement, DragSource.StartPoint);
            DragDropEffects    supportedEffects = adv.SupportedEffects;

            adv.SourceUI = uiObject as UIElement;

            // Perform DragDrop
            DragDropEffects effects = System.Windows.DragDrop.DoDragDrop(DragSource.DraggedElement, data, supportedEffects);

            adv.FinishDrag(DragSource.DraggedElement, effects);

            // Clean up
            Mouse.Capture(null);
            DragSource   = null;
            adv.SourceUI = null;
        }
        //private static WeakReference _CurrentDropTargetAdvisor = new WeakReference(null);
        //private static IDropTargetAdvisor CurrentDropTargetAdvisor
        //{
        //    get { return _CurrentDropTargetAdvisor.Target as IDropTargetAdvisor; }
        //    set { _CurrentDropTargetAdvisor.Target = value; }
        //}

        #region Dependency Properties Getter/Setters

        public static void SetDragSourceAdvisor(DependencyObject depObj, IDragSourceAdvisor advisor)
        {
            depObj.SetValue(DragSourceAdvisorProperty, advisor);
        }
        private static void DragStarted(UIElement uiElt)
        {
            _isMouseDown = false;
            Mouse.Capture(uiElt);

            DataObject data = CurrentDragSourceAdvisor.GetDataObject(_draggedElt);

            data.SetData(DragOffsetFormat, _offsetPoint);
            DragDropEffects supportedEffects = CurrentDragSourceAdvisor.SupportedEffects;

            // Perform DragDrop

            DragDropEffects effects = System.Windows.DragDrop.DoDragDrop(_draggedElt, data, supportedEffects);
            CurrentDragSourceAdvisor.FinishDrag(data, effects, _IsDropCompletedOK);

            // Clean up
            RemovePreviewAdorner();
            Mouse.Capture(null);
            _draggedElt = null;
            CurrentDragSourceAdvisor = null;
            _IsDropCompletedOK = false;
        }
        /* ____________________________________________________________________
         *		Drag Source events 
         * ____________________________________________________________________
         */

        private static void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Make this the new drag source
            CurrentDragSourceAdvisor = GetDragSourceAdvisor(sender as DependencyObject);

            //UIElement candidat = e.Source as UIElement;

            //if (CurrentDragSourceAdvisor.IsDraggable(candidat) == false)
            //{
            //    candidat = e.OriginalSource as UIElement;

            //    if (CurrentDragSourceAdvisor.IsDraggable(candidat) == false)
            //        return;
            //}

            UIElement candidat = e.OriginalSource as UIElement;

            if (CurrentDragSourceAdvisor.IsDraggable(candidat) == false)
            {
                candidat = e.Source as UIElement;

                if (CurrentDragSourceAdvisor.IsDraggable(candidat) == false)
                    return;
            }

            _draggedElt = candidat;
            _dragStartPoint = e.GetPosition(null);
            _offsetPoint = e.GetPosition(_draggedElt);
            _isMouseDown = true;
        }
Пример #13
0
 public static void SetDragSourceAdvisor(DependencyObject depObj,
                                         IDragSourceAdvisor advisor)
 {
     depObj.SetValue(DragSourceAdvisorProperty, advisor);
 }
Пример #14
0
		public static void SetDragSourceAdvisor(UIElement depo, IDragSourceAdvisor advisor)
		{
			depo.SetValue(DragSourceAdvisorProperty, advisor);
		}
Пример #15
0
 public static void SetDragSourceAdvisor(UIElement depo, IDragSourceAdvisor advisor)
 {
     depo.SetValue(DragSourceAdvisorProperty, advisor);
 }