/// <summary>
 /// Initializes a new instance of the <see cref="DropCompletedEventArgs"/> class.
 /// If the event is a preview, <see cref="CloneList"/> is always empty.
 /// </summary>
 /// <param name="routedEvent">The event that occured.</param>
 /// <param name="dragSource">The drag source.</param>
 /// <param name="dropDestinationItem">The destination of the drop.</param>
 /// <param name="effect">The drop effect.</param>
 /// <param name="itemList">The list of moved items.</param>
 /// <param name="cloneList">The list of cloned items.</param>
 internal DropCompletedEventArgs(RoutedEvent routedEvent, IDragSourceControl dragSource, object dropDestinationItem, DragDropEffects effect, IList itemList, IList cloneList)
     : base(routedEvent, dragSource)
 {
     DropDestinationItem = dropDestinationItem;
     Effect    = effect;
     ItemList  = itemList;
     CloneList = cloneList;
 }
        /// <summary>
        /// Gets the drag source from arguments of a drag drop event.
        /// </summary>
        /// <param name="e">The event data.</param>
        /// <param name="dragSource">The drag source upon return.</param>
        /// <returns>True if successful.</returns>
        protected virtual bool GetValidDragSourceFromArgs(DragEventArgs e, out IDragSourceControl dragSource)
        {
            if (e.Data.GetDataPresent(DragSource.GetType()))
            {
                if (e.Data.GetData(DragSource.GetType()) is IDragSourceControl AsDragSource)
                {
                    if (AsDragSource.HasDragItemList(out object RootItem, out IList _) && IsSameTypeAsContent(RootItem))
                    {
                        dragSource = AsDragSource;
                        return(true);
                    }
                }
            }

            Contract.Unused(out dragSource);
            return(false);
        }
        /// <summary>
        /// Gets the drag target from arguments of a drag drop event.
        /// </summary>
        /// <param name="e">The event data.</param>
        /// <param name="asDragSource">The drag source.</param>
        /// <param name="destinationItem">The drag target upon return.</param>
        /// <returns>True if successful.</returns>
        protected virtual bool GetValidDropDestinationFromArgs(DragEventArgs e, IDragSourceControl asDragSource, out object destinationItem)
        {
            if (DropTargetContainer != null)
            {
                object DropDestinationItem = DropTargetContainer.Content;

                if (asDragSource.SourceGuid == DragSource.SourceGuid)
                {
                    if (!asDragSource.IsDraggedItemParent(DropDestinationItem) || (e.AllowedEffects.HasFlag(DragDropEffects.Copy) && e.KeyStates.HasFlag(DragDropKeyStates.ControlKey)))
                    {
                        if (!asDragSource.HasDragItemList(out _, out IList FlatItemList) || !FlatItemList.Contains(DropDestinationItem))
                        {
                            destinationItem = DropDestinationItem;
                            return(true);
                        }
                    }
                }
            }

            Contracts.Contract.Unused(out destinationItem);
            return(false);
        }
        /// <summary>
        /// Invoked when an unhandled <see cref="UIElement.Drop"/> attached event reaches an element in its route that is derived from this class.
        /// </summary>
        /// <param name="e">The event data.</param>
        protected override void OnDrop(DragEventArgs e)
        {
            e.Effects = GetAllowedDropEffects(e);
            e.Handled = true;

            if (e.Effects != DragDropEffects.None)
            {
                ExtendedTreeViewItemBase?ItemContainer = GetEventSourceItem(e);
                IDragSourceControl       AsDragSource  = (IDragSourceControl)e.Data.GetData(DragSource.GetType());
                bool   IsDragPossible  = AsDragSource.IsDragPossible(out object SourceItem, out IList ItemList);
                object?DestinationItem = ItemContainer != null ? ItemContainer.Content : null;

                UnselectAll();

                if (IsDragPossible && DestinationItem != null)
                {
                    IList CloneList = CreateItemList();

                    Debug.Assert(CloneList.Count == 0);
                    NotifyPreviewDropCompleted(DestinationItem, e.Effects, ItemList, CloneList);

                    if (e.Effects == DragDropEffects.Copy)
                    {
                        DragDropCopy(SourceItem, DestinationItem, ItemList, CloneList);
                    }
                    else if (e.Effects == DragDropEffects.Move)
                    {
                        DragDropMove(SourceItem, DestinationItem, ItemList);
                    }

                    Debug.Assert(CloneList.Count > 0 || e.Effects != DragDropEffects.Copy);
                    NotifyDropCompleted(DestinationItem, e.Effects, ItemList, CloneList);

                    Expand(DestinationItem);
                }
            }
        }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DropCheckEventArgs"/> class.
 /// </summary>
 /// <param name="routedEvent">The event that occured.</param>
 /// <param name="dragSource">The drag source.</param>
 /// <param name="dropDestinationItem">The destination of the drop.</param>
 /// <param name="permission">The permission token.</param>
 internal DropCheckEventArgs(RoutedEvent routedEvent, IDragSourceControl dragSource, object dropDestinationItem, PermissionToken permission)
     : base(routedEvent, dragSource)
 {
     DropDestinationItem = dropDestinationItem;
     Permission          = permission;
 }
Exemple #6
0
 internal DragStartingEventArgs(RoutedEvent routedEvent, IDragSourceControl dragSource, CancellationToken cancellation)
     : base(routedEvent, dragSource)
 {
     this.Cancellation = cancellation;
 }
Exemple #7
0
 /// <summary>
 /// Clears the dragged items.
 /// </summary>
 /// <param name="dragSource">The drag source.</param>
 protected abstract void ClearDragItemList(IDragSourceControl dragSource);
Exemple #8
0
 /// <summary>
 /// Sets the dragged items.
 /// </summary>
 /// <param name="dragSource">The drag source.</param>
 /// <param name="itemList">The list of dragged items.</param>
 protected abstract void SetDragItemList(IDragSourceControl dragSource, IList itemList);
 /// <summary>
 /// Initializes a new instance of the <see cref="DragDropEventArgs"/> class.
 /// </summary>
 /// <param name="routedEvent">The event that occured.</param>
 /// <param name="dragSource">The drag source.</param>
 internal DragDropEventArgs(RoutedEvent routedEvent, IDragSourceControl dragSource)
     : base(routedEvent)
 {
     DragSource = dragSource;
 }
Exemple #10
0
 /// <summary>
 /// Clears the dragged items.
 /// </summary>
 /// <param name="dragSource">The drag source.</param>
 protected override void ClearDragItemList(IDragSourceControl dragSource)
 {
     dragSource.ClearFlatDraggedItemList();
 }
Exemple #11
0
 /// <summary>
 /// Sets the dragged items.
 /// </summary>
 /// <param name="dragSource">The drag source.</param>
 /// <param name="itemList">The list of dragged items.</param>
 protected override void SetDragItemList(IDragSourceControl dragSource, IList itemList)
 {
     dragSource.SetFlatDraggedItemList(Content, FlatItemList(itemList));
 }
Exemple #12
0
 internal DropCompletedEventArgs(RoutedEvent routedEvent, IDragSourceControl dragSource, object dropDestinationItem, IList cloneList)
     : base(routedEvent, dragSource)
 {
     this.DropDestinationItem = dropDestinationItem;
     this.CloneList           = cloneList;
 }