/// <summary> /// First determine whether the drag data is supported. /// Second determine whether or not a Move can be done. /// And finally handle the actual drop when <code>bDrop</code> is true. /// </summary> /// <param name="bDrop">True to perform an actual drop, otherwise just return e.Effects</param> /// <param name="sender">DragDrop event <code>sender</code></param> /// <param name="e">DragDrop event arguments</param> private void DragOverOrDrop(bool bDrop, object sender, DragEventArgs e) { ToolBarDataProvider <TContainer, TObject> dataProvider = this.GetData(e) as ToolBarDataProvider <TContainer, TObject>; if (dataProvider != null) { TContainer dragSourceContainer = dataProvider.SourceContainer as TContainer; TObject dragSourceObject = dataProvider.SourceObject as TObject; if (dragSourceObject == null) { dragSourceObject = Utilities.FindParentControlIncludingMe <TObject>(dataProvider.SourceObject as DependencyObject); } Debug.Assert(dragSourceObject != null); Debug.Assert(dragSourceContainer != null); Panel dropContainer = sender as Panel; if (dropContainer != null) { if (bDrop) { dataProvider.Unparent(); Point containerPoint = e.GetPosition(dropContainer); Point objectPoint = dataProvider.StartPosition; #if REUSE_SAME_BUTTON //|| true dropContainer.Children.Add(dragSourceObject); Canvas.SetLeft(dragSourceObject, containerPoint.X - objectPoint.X); Canvas.SetTop(dragSourceObject, containerPoint.Y - objectPoint.Y); #else Button oldButton = dragSourceObject as Button; Button newButton = new Button(); newButton.Content = Utilities.CloneElement(oldButton.Content); newButton.ToolTip = oldButton.ToolTip; dropContainer.Children.Add(newButton); Canvas.SetLeft(newButton, containerPoint.X - objectPoint.X); Canvas.SetTop(newButton, containerPoint.Y - objectPoint.Y); #endif } e.Effects = DragDropEffects.Move; e.Handled = true; } else { e.Effects = DragDropEffects.None; e.Handled = true; } } }
/// <summary> /// First determine whether the drag data is supported. /// Second determine what operation to do (move, link). /// And finally handle the actual drop when <code>bDrop</code> is true. /// Insert the button if the target is another button, otherwise /// just add it to the end of the list. /// </summary> /// <param name="bDrop">True to perform an actual drop, otherwise just return e.Effects</param> /// <param name="sender">DragDrop event <code>sender</code></param> /// <param name="e">DragDrop event arguments</param> private void DragOverOrDrop(bool bDrop, object sender, DragEventArgs e) { ToolBarDataProvider <TContainer, TObject> dataProvider = this.GetData(e) as ToolBarDataProvider <TContainer, TObject>; if (dataProvider != null) { TContainer dragSourceContainer = dataProvider.SourceContainer as TContainer; TObject dragSourceObject = dataProvider.SourceObject as TObject; Debug.Assert(dragSourceObject != null); Debug.Assert(dragSourceContainer != null); TContainer dropContainer = sender as TContainer; TObject dropTarget = e.Source as TObject; if (dropTarget == null) { dropTarget = Utilities.FindParentControlExcludingMe <TObject>(e.Source as DependencyObject); } if (dropContainer != null) { if (bDrop) { dataProvider.Unparent(); if (dropTarget == null) { dropContainer.Items.Add(dragSourceObject); } else { dropContainer.Items.Insert(dropContainer.Items.IndexOf(dropTarget), dragSourceObject); } } e.Effects = (dropTarget == null) ? DragDropEffects.Move : DragDropEffects.Link; e.Handled = true; } else { e.Effects = DragDropEffects.None; e.Handled = true; } } }