gong-wpf-dragdrop icon indicating copy to clipboard operation
gong-wpf-dragdrop copied to clipboard

Effects adorner offscreen and hiding inappropriate drag adorner

Open uecasm opened this issue 5 years ago • 4 comments

What steps will reproduce this issue?

  • [x] The first problem is that the Effect adorner gets clipped at the window edges; this appears to have been previously solved for the Drag adorner (#69), so perhaps that existing solution just needs to be applied to both?

  • [ ] The second problem is a more general one that the Effect adorner doesn't appear to be template-customisable based on the drop target (other than supplying EffectText and DestinationText, which in turn can't be used in a purely XAML template). This might be a "too hard basket" issue to actually solve for now, but bears mentioning.

  • [x] The third problem is that (after switching to use the Drag adorner instead of the Effect adorner due to the above two problems), the Drag adorner ends up being displayed inappropriately in the case when dragging items inside the second tab.

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

  • GongSolutions.WPF.DragDrop 2.0.3
  • Windows 8.1.1
  • Visual Studio 2017
  • .NET Framework 4.6.2

uecasm avatar Jul 24 '19 01:07 uecasm

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.)

uecasm avatar Jul 24 '19 01:07 uecasm

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

punker76 avatar Sep 10 '19 21:09 punker76

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 avatar Mar 13 '20 15:03 Jammyo

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:

  • Inside DragDrop.CreateEffectAdorner(): Set adornment.Tag = dropInfo;
  • In the .xaml add an adorner template, i.e: dd:DragDrop.EffectMoveAdornerTemplate="{DynamicResource MoveEffectAdornerTemplate}"
  • Create a resource for this template, and access the Tag through a Binding: Text="{Binding Path=Tag.EffectText, RelativeSource={RelativeSource TemplatedParent}}"

My adorner resource then looks like this: <TabItem.Resources> <DataTemplate x:Key="MoveEffectAdornerTemplate"> <Border BorderBrush="Chartreuse" BorderThickness="3"> <TextBlock Text="{Binding Path=Tag.EffectText, RelativeSource={RelativeSource TemplatedParent}}" /> </Border> </DataTemplate> </TabItem.Resources>

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?

Jammyo avatar Mar 17 '20 12:03 Jammyo