public virtual void Drop(DropInfo dropInfo)
        {
            int insertIndex = dropInfo.InsertIndex;
            IList destinationList = GetList(dropInfo.TargetCollection);
            IEnumerable data = ExtractData(dropInfo.Data);

            if (dropInfo.DragInfo.VisualSource == dropInfo.VisualTarget)
            {
                IList sourceList = GetList(dropInfo.DragInfo.SourceCollection);

                foreach (object o in data)
                {
                    int index = sourceList.IndexOf(o);

                    if (index != -1)
                    {
                        sourceList.RemoveAt(index);
                        
                        if (sourceList == destinationList && index < insertIndex)
                        {
                            --insertIndex;
                        }
                    }
                }
            }

            foreach (object o in data)
            {
                destinationList.Insert(insertIndex++, o);
            }
        }
 public virtual void DragOver(DropInfo dropInfo)
 {
     if (CanAcceptData(dropInfo))
     {
         dropInfo.Effects = DragDropEffects.Copy;
         dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
     }
 }
 protected static bool CanAcceptData(DropInfo dropInfo)
 {
     if (dropInfo.DragInfo.SourceCollection == dropInfo.TargetCollection)
     {
         return GetList(dropInfo.TargetCollection) != null;
     }
     else if (dropInfo.DragInfo.SourceCollection is ItemCollection)
     {
         return false;
     }
     else
     {
         if (TestCompatibleTypes(dropInfo.TargetCollection, dropInfo.Data))
         {
             return !IsChildOf(dropInfo.VisualTargetItem, dropInfo.DragInfo.VisualSourceItem);
         }
         else
         {
             return false;
         }
     }
 }
Example #4
0
        static void DropTarget_PreviewDrop(object sender, DragEventArgs e)
        {
            DropInfo dropInfo = new DropInfo(sender, e, m_DragInfo, m_Format.Name);
            IDropTarget dropHandler = GetDropHandler((UIElement)sender);

            DragAdorner = null;
            DropTargetAdorner = null;

            if (dropHandler != null)
            {
                dropHandler.Drop(dropInfo);
            }
            else
            {
                DefaultDropHandler.Drop(dropInfo);
            }

            e.Handled = true;
        }
Example #5
0
        static void DropTarget_PreviewDragOver(object sender, DragEventArgs e)
        {
            DropInfo dropInfo = new DropInfo(sender, e, m_DragInfo, m_Format.Name);
            IDropTarget dropHandler = GetDropHandler((UIElement)sender);

            if (dropHandler != null)
            {
                dropHandler.DragOver(dropInfo);
            }
            else
            {
                DefaultDropHandler.DragOver(dropInfo);
            }

            // Update the drag adorner.
            if (dropInfo.Effects != DragDropEffects.None)
            {
                if (DragAdorner == null && m_DragInfo != null)
                {
                    CreateDragAdorner();
                }

                if (DragAdorner != null)
                {
                    DragAdorner.MousePosition = e.GetPosition(DragAdorner.AdornedElement);
                    DragAdorner.InvalidateVisual();
                }
            }
            else
            {
                DragAdorner = null;
            }

            // If the target is an ItemsControl then update the drop target adorner.
            if (sender is ItemsControl)
            {
                UIElement adornedElement = ((ItemsControl)sender).GetVisualDescendent<ItemsPresenter>();

                if (dropInfo.DropTargetAdorner == null)
                {
                    DropTargetAdorner = null;
                }
                else if (!dropInfo.DropTargetAdorner.IsInstanceOfType(DropTargetAdorner))
                {
                    DropTargetAdorner = DropTargetAdorner.Create(dropInfo.DropTargetAdorner, adornedElement);
                }

                if (DropTargetAdorner != null)
                {
                    DropTargetAdorner.DropInfo = dropInfo;
                    DropTargetAdorner.InvalidateVisual();
                }
            }

            e.Effects = dropInfo.Effects;
            e.Handled = true;

            Scroll((DependencyObject)sender, e);
        }
Example #6
0
        void IDropTarget.Drop(DropInfo dropInfo)
        {
                       
            DirectoryViewModel sourceItem = (DirectoryViewModel)dropInfo.Data;
            //OriginalImage targetItem = (OriginalImage)dropInfo.TargetItem;
            //Uri uri = new Uri("pack://application:,,,/Views/Images/image.png");
            string name = "";
            if (sourceItem.IsDirectory)
            {
                // Circular progress Bar is called when we drop a directory
                this.IsCircularProgressBarVisible = "Visible";
                this.IsAlgorithmsEnabled = false;
                this._vmain.circularProgressBar.StartDelay();                

                
                List<string> droppedImages = null; ;

                // Thread that get the directory files recursive 
                Thread progressThread = new Thread(delegate()
                    {
                        try
                        {       
                           droppedImages = FileHelper.GetFilesRecursive(sourceItem.FullName);                            
                           this._vmain.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.DataBind, (SendOrPostCallback)delegate
                               {

                                   //Disable Circular progress Bar because the directory drop is done
                                   this.IsCircularProgressBarVisible = "Hidden";
                                   this._vmain.circularProgressBar.StopSpinning();
                                   this.IsAlgorithmsEnabled = true;
                                   
                                   for (int i = 0; i < droppedImages.Count; i++)
                                   {
                                       name = "img" + this._oimages.Count.ToString(); // +"-o";
                                       this._oimages.Add(new OriginalCollectionViewModel(new ImageModel(name, droppedImages[i]), false));
                                   }

                               }, null);
                        }
                        catch (Exception e)
                        {
                            //
                        }
                        
                    });

                progressThread.Priority = ThreadPriority.Highest;           
                progressThread.Start();

            }
            else
            {
                name = "img" + this._oimages.Count.ToString(); // +"-o";
                this._oimages.Add(new OriginalCollectionViewModel(new ImageModel(name, sourceItem.FullName), false)); 
            }            
        }
Example #7
0
        void IDropTarget.DragOver(DropInfo dropInfo)
        {
            DirectoryViewModel sourceItem = dropInfo.Data as DirectoryViewModel;
            //OriginalImage targetItem = dropInfo.TargetItem as OriginalImage;

            if (sourceItem != null)
            {
                dropInfo.DropTargetAdorner = DropTargetAdorners.Highlight;
                dropInfo.Effects = DragDropEffects.Copy;
            }
        }