Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Effects adorner offscreen and hiding inappropriate drag adorner #325

Open
2 of 3 tasks
uecasm opened this issue Jul 24, 2019 · 4 comments
Open
2 of 3 tasks

Effects adorner offscreen and hiding inappropriate drag adorner #325

uecasm opened this issue Jul 24, 2019 · 4 comments
Labels

Comments

@uecasm
Copy link

uecasm commented Jul 24, 2019

What steps will reproduce this issue?

  • 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 (Drag Adorner Gets Clipped #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.

  • 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
Copy link
Author

uecasm commented Jul 24, 2019

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
Copy link
Owner

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
Copy link

Jammyo commented Mar 13, 2020

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
Copy link

Jammyo commented Mar 17, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants