punker76 / gong-wpf-dragdrop

The GongSolutions.WPF.DragDrop library is a drag'n'drop framework for WPF
BSD 3-Clause "New" or "Revised" License
2.3k stars 400 forks source link

Effects adorner offscreen and hiding inappropriate drag adorner #325

Open uecasm opened 5 years ago

uecasm commented 5 years ago

What steps will reproduce this issue?

Expected outcome

More explanation of the intended and observed behaviour can be found in the readme in the repository below.

It's possible that some of this is already solvable using existing features of the library, but there really isn't much documentation for it, and even reading the code it can be hard to understand what some properties are for. (It would also be nice if you provided a pre-compiled Release of the Showcase app, so that people don't have to install additional tools to compile it themselves.)

Repo

https://github.com/uecasm/gong-test-1

Environment

uecasm commented 5 years ago

I can partially solve the third problem by moving the DragDrop properties to the Header of the TabItem rather than on the TabItem itself -- ie. the second TabItem becomes:

        <TabItem>
            <TabItem.Header>
                <TextBlock Text="Group Two"
                           dd:DragDrop.IsDropTarget="True"
                           dd:DragDrop.DropHandler="{Binding}"
                           dd:DragDrop.ShowAlwaysDropTargetAdorner="True"
                           dd:DragDrop.DropAdornerTemplate="{StaticResource DragToGroup2Template}" />
            </TabItem.Header>
            <ListBox Margin="5" ItemsSource="{Binding Group2}" HorizontalContentAlignment="Stretch"
                     dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True"
                     dd:DragDrop.DropHandler="{Binding}"
                     dd:DragDrop.DragDirectlySelectedOnly="True"
                     dd:DragDrop.DragAdornerTemplate="{StaticResource DragItemTemplate}"
                     dd:DragDrop.UseDefaultEffectDataTemplate="True" />
        </TabItem>

(Also need to change TabItem to TextBlock in the DragOver handler. In real code this probably should be done a different way, eg. by using a different DropHandler.)

You can see this change at https://github.com/uecasm/gong-test-1/tree/textblock-header.

This fixes the problem of the wrong Drag adorner being displayed while dragging an item from group 2's listbox around inside that listbox.

However it still displays that adorner when dragging an item from group 2's list over the group 2 tab header, which I don't want. (The effect adorner appears to be smart enough to hide itself for that case.)

punker76 commented 5 years ago

Part one is fixed and available with v2.0.6

It's possible that some of this is already solvable using existing features of the library, but there really isn't much documentation for it, and even reading the code it can be hard to understand what some properties are for. (It would also be nice if you provided a pre-compiled Release of the Showcase app, so that people don't have to install additional tools to compile it themselves.)

A pre-compiled showcase app is available on every release https://github.com/punker76/gong-wpf-dragdrop/releases

Jammyo commented 4 years ago

Configurable effects adorner would be amazing! I think have the same use case - I want to provide a short explanation tooltip about why a drag-drop operation is invalid (due to constraints placed on which items can be copied to other lists).

I can achieve this with the default effect data template, because I can supply the contextual information from the ViewModel in the form of effect text and destination text. However there's no way to configure the look and feel to match my app.

The only alternatives are to supply a custom drop target adorner to render a tooltip, (which almost works, except the adorner is clipped at the boundaries of the element I'm dragging to), or else to use an EffectAdornerTemplate (in which case I can't dynamically set the text).

I'd be happy to do the work and create a P/R, but I have no idea where to start. Any suggestions?

Jammyo commented 4 years ago

So I've had a look over the past few days, and after learning a bunch of stuff about WPF which I haven't needed to know until now, I have a solution of sorts. I'm not sure if it's good practice or not though, it certainly seems a bit hacky to me. What I did:

My adorner resource then looks like this: `

` I'd be happy to create a pull request, but since 'Tag' in Path=Tag.EffectText is not resolvable at compile time, I think this is probably not a great solution for a library like this. Thoughts?