More Info : TabControl support

DragDropEventProcessor allow user to do Shell based Drag and Drop (e.g. via IDataObject), which initialize when mouse down over a selected item and drag.

A menu is shown (with allow to choose DragDropEffects) if the drag/drop operation is initialized from and to the same application (not same window), using right mouse button.
FileExplorer3.DropnDrop.png
Touch is not enabled, use DragDropLiteEventProcessor instead.

To enable drag / drop, add this processor to UIEventAdapter.Processors.
 <bc:DragDropEventProcessor EnableDrag="{Binding EnableDrag}" EnableDrop="{Binding EnableDrop}" />


To support drag, you have to implement ISupportShellDrag or ISupportShellDragHelper, which allow return dragging items and converter to DataObject.

To support drop, you have to implement ISupportShellDrop or ISupportShellDropHelper, which query and complete the drag and drop operations.

In most case you can use the implemented LambdaShellDragHelper, ShellDragHelper or ShellDragHelper<T> and LambdaShellDrogHelper, ShellDropHelper or ShellDropHelper<T>.

e.g. (taken from Test_ShellDragDemo)
DragHelper = new LambdaShellDragHelper<FileModel>(
      //Convert IDraggable (FileViewModel) to M (FileModel), ConvertBack is used.
    _fileModelConverter,
     //Convert IEnumerable<M> (IEnumerable<FileModel>) to IDataObject, Convert is used.
    _dataObjectConverter, 
    () => Items.Where(fvm => fvm.IsSelected).Select(fvm => fvm.Model),
    (fmList) => DragDropEffects.Link | DragDropEffects.Copy | DragDropEffects.Move, //QueryDrag
    (fmList, da, effect) => //OnDragCompleted
    {
        if (effect == DragDropEffects.Move)
            foreach (var f in fmList)
            {
                var foundItem = Items.FirstOrDefault(fvm => fvm.Model.Equals(f));
                if (foundItem != null)
                    Items.Remove(foundItem);
            }
    });

DropHelper = new LambdaShellDropHelper<FileModel>(
     //Convert IDraggable (FileViewModel) to M (FileModel), Convert is used.
    _fileModelConverter,  
     //Convert IEnumerable<M> (IEnumerable<FileModel>) to IDataObject, ConvertBack is used.
    _dataObjectConverter, 
    (fms, eff) => //QueryDrop(IEnumerable<FileModel>, DragDropEffects) : QueryDropEffects
    {
        IEnumerable<FileModel> itemsModel = Items.Select(fvm => fvm.Model);
        if (fms.Any(f => itemsModel.Contains(f)))
            return QueryDropEffects.None;
        return QueryDropEffects.CreateNew(eff & (DragDropEffects.Link | DragDropEffects.Move), eff & DragDropEffects.Move);

    },
    (fms, da, eff) => //Drop(IEnumerable<FileModel>, IDataObject, DragDropEffects) : DragDropEffects
    {
        foreach (var existingFvm in Items) existingFvm.IsSelected = false;
        foreach (var fm in fms) Items.Add(new FileViewModel(fm));
        if (eff.HasFlag(DragDropEffects.Move))
            return DragDropEffects.Move;
        if (eff.HasFlag(DragDropEffects.Copy))
            return DragDropEffects.Copy;
        return DragDropEffects.Link;
    }) { DisplayName = label };



ShellDragDemo.png

Implementations
DragDropUIEventProcessor.png
p.s. Changed, see source

Last edited Oct 17, 2014 at 5:30 PM by lycj, version 14

Comments

No comments yet.