Beispiel #1
0
 static void gallery_Drop(object sender, DragEventArgs e)
 {
     e.Handled = true;
     if (dragableItem != null)
     {
         HitTestResult res = VisualTreeHelper.HitTest((GalleryControl)sender, e.GetPosition((GalleryControl)sender));
         if (res.VisualHit == null)
         {
             return;
         }
         GalleryItemControl target = LayoutHelper.FindParentObject <GalleryItemControl>(res.VisualHit);
         if (target != null && target.Item != dragableItem)
         {
             GalleryItemCollection targetCollection = target.Item.Group.Items;
             GalleryItemCollection sourceCollection = dragableItem.Group.Items;
             int targetIndex = targetCollection.IndexOf(target.Item);
             if (targetCollection == sourceCollection)
             {
                 targetCollection.Move(originalIndex, targetIndex);
             }
             else
             {
                 sourceCollection.Remove(dragableItem);
                 targetCollection.Insert(targetIndex, dragableItem);
             }
             dragableItem = null;
         }
     }
 }
Beispiel #2
0
        private void OnGalleryControlDragDrop(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(typeof(List <GalleryItem>)) || DragSource == null)
            {
                return;
            }
            GalleryControl dragTarget = (GalleryControl)sender;
            RibbonHitInfo  hitInfo    = dragTarget.CalcHitInfo(dragTarget.PointToClient(new Point(e.X, e.Y)));
            GalleryItem    targetItem = hitInfo.GalleryItem;

            if (targetItem != null)
            {
                GalleryItemCollection target = targetItem.GalleryGroup.Items;
                int index = target.IndexOf(targetItem);
                List <GalleryItem> draggedItems = (List <GalleryItem>)e.Data.GetData(typeof(List <GalleryItem>));
                foreach (GalleryItem item in draggedItems)
                {
                    GalleryItemCollection source = item.GalleryGroup.Items;
                    source.Remove(item);
                    target.Insert(index++, item);
                }
            }
            targetHighlightItem = null;
        }