/// <summary>
        /// Method called on Drop events</summary>
        /// <param name="e">DragEventArgs containing event information</param>
        protected override void OnDrop(DragEventArgs e)
        {
            object target = GetDropTarget(e);

            if (!ApplicationUtil.CanInsert(AssociatedObject.DataContext, target, e.Data))
            {
                return;
            }

            IDataObject dataObject = e.Data;

            if ((e.AllowedEffects & DragDropEffects.Copy) > 0 &&
                (e.KeyStates & DragDropKeyStates.ControlKey) > 0)
            {
                var registry = Composer.Current.Container.GetExportedValueOrDefault <IContextRegistry>();
                if (registry != null)
                {
                    // Attempt to get context which was the source of this drag operation
                    var ctx = registry.GetActiveContext <IInstancingContext>();
                    if (ctx != null && ctx.CanCopy())
                    {
                        object rawObject = ctx.Copy();
                        dataObject = rawObject as IDataObject ?? new DataObject(rawObject);
                    }
                }
            }

            var statusService = Composer.Current.Container.GetExportedValueOrDefault <IStatusService>();

            ApplicationUtil.Insert(AssociatedObject.DataContext, target, dataObject, "Drag Drop".Localize(), statusService);

            e.Effects = DragDropEffects.None;
            e.Handled = true;
        }
        //private void CreateInsertionAdorner()
        //{
        //   // var adornerLayer = AdornerLayer.GetAdornerLayer(this.targetItemContainer);
        //   // this.insertionAdorner = new InsertionAdorner(this.hasVerticalOrientation, this.isInFirstHalf, this.targetItemContainer, adornerLayer);
        //}

        /// <summary>
        /// Method called on DragOver events</summary>
        /// <param name="e">DragEventArgs containing event information</param>
        protected override void OnDragOver(DragEventArgs e)
        {
            var source = (DependencyObject)e.OriginalSource;

            FrameworkElement container = null;

            var tv = AssociatedObject as TreeView;

            if (tv != null)
            {
                container = source.FindAncestor <TreeViewItem>();
            }
            else
            {
                container = AssociatedObject.ContainerFromElement(source) as FrameworkElement;
            }

            object parentData = container != null ? container.DataContext : AssociatedObject.DataContext;

            if (ApplicationUtil.CanInsert(AssociatedObject.DataContext, parentData, e.Data))
            {
                if ((e.AllowedEffects & DragDropEffects.Copy) > 0 &&
                    (e.KeyStates & DragDropKeyStates.ControlKey) > 0)
                {
                    e.Effects = DragDropEffects.Copy;
                }
                else
                {
                    e.Effects = DragDropEffects.Move;
                }
                e.Handled = true;
            }
        }
Example #3
0
 /// <summary>
 /// Event fired when an item is dragged over the control</summary>
 /// <param name="e">Event args</param>
 protected override void OnDragOver(DragEventArgs e)
 {
     if (ApplicationUtil.CanInsert(AssociatedObject.DataContext, null, e.Data))
     {
         e.Effects = DragDropEffects.Move;
         e.Handled = true;
     }
 }
Example #4
0
 /// <summary>
 /// Event fired when an item is dropped onto the control</summary>
 /// <param name="e">Event args</param>
 protected override void OnDrop(DragEventArgs e)
 {
     if (ApplicationUtil.CanInsert(AssociatedObject.DataContext, null, e.Data))
     {
         var statusService = Composer.Current.Container.GetExportedValueOrDefault <IStatusService>();
         ApplicationUtil.Insert(AssociatedObject.DataContext, null, e.Data, "Drag Drop".Localize(), statusService);
         e.Effects = DragDropEffects.None;
         e.Handled = true;
     }
 }
        /// <summary>
        /// Method called on DragOver events</summary>
        /// <param name="e">DragEventArgs containing event information</param>
        protected override void OnDragOver(DragEventArgs e)
        {
            int  insertionIndex = AssociatedObject.Items.Count;
            bool isInFirstHalf  = false;

            var source = (DependencyObject)e.OriginalSource;

            FrameworkElement container = null;

            var tv = AssociatedObject as TreeView;

            if (tv != null)
            {
                container = source.FindAncestor <TreeViewItem>();
            }
            else
            {
                container = AssociatedObject.ContainerFromElement(source) as FrameworkElement;
            }

            if (container != null)
            {
                Point positionRelativeToItemContainer = e.GetPosition(container);
                isInFirstHalf = IsInFirstHalf(container, positionRelativeToItemContainer, m_hasVerticalOrientation);

                ItemsControl itemsControl = ItemsControl.ItemsControlFromItemContainer(container);
                insertionIndex = itemsControl.ItemContainerGenerator.IndexFromContainer(container);

                if (!isInFirstHalf)
                {
                    insertionIndex++;
                }
            }

            object parentData = container != null ? container.DataContext : AssociatedObject.DataContext;

            if (ApplicationUtil.CanInsert(AssociatedObject.DataContext, parentData, e.Data))
            {
                if ((e.AllowedEffects & DragDropEffects.Copy) > 0 &&
                    (e.KeyStates & DragDropKeyStates.ControlKey) > 0)
                {
                    e.Effects = DragDropEffects.Copy;
                }
                else
                {
                    e.Effects = DragDropEffects.Move;
                }
                e.Handled = true;
            }
        }
        /// <summary>
        /// Handle Drop event</summary>
        /// <param name="e">Drag event arguments</param>
        protected override void OnDrop(DragEventArgs e)
        {
            var pos    = e.GetPosition(AssociatedObject);
            var parent = AssociatedObject.GetItemAtPoint(pos);

            if (parent == null)
            {
                parent = AssociatedObject.DataContext;
            }

            if (ApplicationUtil.CanInsert(AssociatedObject.DataContext, parent, e.Data))
            {
                var statusService = Composer.Current.Container.GetExportedValueOrDefault <IStatusService>();
                ApplicationUtil.Insert(AssociatedObject.DataContext, parent, e.Data, "Drag Drop".Localize(), statusService);
                e.Effects = DragDropEffects.None;
                e.Handled = true;
            }
        }
        /// <summary>
        /// Handle DragOver event</summary>
        /// <param name="e">Drag event arguments</param>
        protected override void OnDragOver(DragEventArgs e)
        {
            object target = GetDropTarget(e);

            if (ApplicationUtil.CanInsert(AssociatedObject.DataContext, target, e.Data))
            {
                if ((e.AllowedEffects & DragDropEffects.Copy) > 0 &&
                    (e.KeyStates & DragDropKeyStates.ControlKey) > 0)
                {
                    e.Effects = DragDropEffects.Copy;
                }
                else
                {
                    e.Effects = DragDropEffects.Move;
                }
            }
            else
            {
                e.Effects = DragDropEffects.None;
            }
            e.Handled = true;
        }