Beispiel #1
0
        protected static bool CanAcceptData(DropInfo dropInfo)
        {
            if (dropInfo.DragInfo == null)
            {
                return(false);
            }

            if (dropInfo.DragInfo.SourceCollection == dropInfo.TargetCollection)
            {
                return(DefaultDropHandler.GetList(dropInfo.TargetCollection) != null);
            }
            else if (dropInfo.DragInfo.SourceCollection is ItemCollection)
            {
                return(false);
            }
            else
            {
                if (DefaultDropHandler.TestCompatibleTypes(dropInfo.TargetCollection, dropInfo.Data))
                {
                    return(!DefaultDropHandler.IsChildOf(dropInfo.VisualTargetItem, dropInfo.DragInfo.VisualSourceItem));
                }
                else
                {
                    return(false);
                }
            }
        }
Beispiel #2
0
        public virtual void Drop(DropInfo dropInfo)
        {
            int         insertIndex     = dropInfo.InsertIndex;
            IList       destinationList = DefaultDropHandler.GetList(dropInfo.TargetCollection);
            IEnumerable data            = DefaultDropHandler.ExtractData(dropInfo.Data);

            if (dropInfo.DragInfo.VisualSource == dropInfo.VisualTarget)
            {
                IList sourceList = DefaultDropHandler.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);
            }
        }
Beispiel #3
0
 public virtual void DragOver(DropInfo dropInfo)
 {
     if (DefaultDropHandler.CanAcceptData(dropInfo))
     {
         dropInfo.Effects           = DragDropEffects.Copy;
         dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
     }
 }
Beispiel #4
0
        protected static bool TestCompatibleTypes(IEnumerable target, object data)
        {
            TypeFilter filter = (t, o) =>
            {
                return(t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable <>));
            };

            var enumerableInterfaces = target.GetType().FindInterfaces(filter, null);
            var enumerableTypes      = from i in enumerableInterfaces select i.GetGenericArguments().Single();

            if (enumerableTypes.Count() > 0)
            {
                Type dataType = TypeUtilities.GetCommonBaseClass(DefaultDropHandler.ExtractData(data));
                return(enumerableTypes.Any(t => t.IsAssignableFrom(dataType)));
            }
            else
            {
                return(target is IList);
            }
        }