Exemplo n.º 1
0
        /// <inheritdoc />
        public virtual void StartDrag(IDragInfo dragInfo)
        {
            var items = TypeUtilities.CreateDynamicallyTypedList(dragInfo.SourceItems).Cast <object>().ToList();

            if (items.Count > 1)
            {
                dragInfo.Data = items;
            }
            else
            {
                // special case: if the single item is an enumerable then we can not drop it as single item
                var singleItem = items.FirstOrDefault();
                if (singleItem is IEnumerable && !(singleItem is string))
                {
                    dragInfo.Data = items;
                }
                else
                {
                    dragInfo.Data = singleItem;
                }
            }

            dragInfo.Effects = dragInfo.Data != null
                ? DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link
                : DragDropEffects.None;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Queries whether a drag can be started.
        /// </summary>
        /// <param name="dragInfo">Information about the drag.</param>
        /// <remarks>
        /// To allow a drag to be started, the <see cref="DragInfo.Effects" /> property on <paramref name="dragInfo" />
        /// should be set to a value other than <see cref="DragDropEffects.None" />.
        /// </remarks>
        public virtual void StartDrag(IDragInfo dragInfo)
        {
            var itemCount = dragInfo.SourceItems.Cast <object>().Count();

            if (itemCount == 1)
            {
                dragInfo.Data = dragInfo.SourceItems.Cast <object>().First();
            }
            else if (itemCount > 1)
            {
                dragInfo.Data = TypeUtilities.CreateDynamicallyTypedList(dragInfo.SourceItems);
            }

            dragInfo.Effects = (dragInfo.Data != null) ? DragDropEffects.Copy | DragDropEffects.Move : DragDropEffects.None;
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public void StartDrag(IDragInfo dragInfo)
        {
            //In our case, the Treeview does not support multiple items, so the drag behavior can't figure it out
            //So we will take care of it ourselves.
            var itemCount = dragInfo.SourceItems.Cast <object>().Count();

            if (itemCount == 1 && SelectedItems.Count == 1)
            {
                dragInfo.Data = TypeUtilities.CreateDynamicallyTypedList(new[] { dragInfo.SourceItems.Cast <object>().First() });
            }
            else if (itemCount == 1 && SelectedItems.Count == 0)
            {
                var dragItem = dragInfo.SourceItems.Cast <object>().First() as ElementModelViewModel;
                if (dragItem != null)
                {
                    dragInfo.Data       = TypeUtilities.CreateDynamicallyTypedList(new[] { dragItem });
                    dragItem.IsSelected = true;
                }
            }
            else if (itemCount > 1)
            {
                dragInfo.Data = TypeUtilities.CreateDynamicallyTypedList(dragInfo.SourceItems);
            }
            else if (SelectedItems.Count > 1 && itemCount == 1)
            {
                if (SelectedItems.Contains(dragInfo.SourceItems.Cast <object>().First()))
                {
                    dragInfo.Data = TypeUtilities.CreateDynamicallyTypedList(SelectedItems);
                }
                else
                {
                    var dragItem = dragInfo.SourceItems.Cast <object>().First() as ElementModelViewModel;
                    if (dragItem != null)
                    {
                        dragInfo.Data = TypeUtilities.CreateDynamicallyTypedList(new[] { dragItem });
                        foreach (var elementModelViewModel in SelectedItems.ToList())
                        {
                            elementModelViewModel.IsSelected = false;
                        }

                        dragItem.IsSelected = true;
                    }
                }
            }

            dragInfo.Effects = (dragInfo.Data != null) ? DragDropEffects.Copy | DragDropEffects.Move : DragDropEffects.None;
        }
Exemplo n.º 4
0
        public static void StartDragWith(this IDragInfo dragInfo, IEnumerable <object> objects)
        {
            var itemCount = objects.Count();

            if (itemCount == 1)
            {
                dragInfo.Data = objects.First();
            }
            else if (itemCount > 1)
            {
                dragInfo.Data = TypeUtilities.CreateDynamicallyTypedList(objects);
            }

            dragInfo.Effects = (dragInfo.Data != null) ?
                               DragDropEffects.Copy | DragDropEffects.Move :
                               DragDropEffects.None;
        }
Exemplo n.º 5
0
        public void StartDrag(AyDragInfo dragInfo)
        {
            int itemCount = dragInfo.SourceItems.Cast <object>().Count();

            if (itemCount == 1)
            {
                dragInfo.Data = dragInfo.SourceItems.Cast <object>().First();
            }
            else if (itemCount > 1)
            {
                dragInfo.Data = TypeUtilities.CreateDynamicallyTypedList(dragInfo.SourceItems);
            }


            dragInfo.Effects = (dragInfo.Data != null) ?
                               DragDropEffects.Copy | DragDropEffects.Move :
                               DragDropEffects.None;
            if (handler22 == null)
            {
                handler22 = new GiveFeedbackEventHandler(DragSource_GiveFeedback);
            }

            dragInfo.VisualSource.GiveFeedback += handler22;
        }