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.25k stars 392 forks source link

DropHandler.Drop & DropHandler.DragOver not being called when default style of Window is overridden. #473

Closed G-Huber closed 2 months ago

G-Huber commented 1 year ago

Describe the bug When my application opens a Window drag & drop does not work for a UserControl inside that window in some circumstances, as Drop or even DragOver of my handlers are not called. The same UserControl inside the main Window works fine.

The bug was noticed in V1.1.0, but is also present in V3.2.1 though in less circumstances. In 1.1.0 it does not work for any of the two ItemControls. In 3.2.1 it does only work one-way from A to B. When dragging from B to A DragOver is called, but even though dropInfo.Effects is set to DragDropEffects.Move, Drop() is never called when releasing the left mouse button.

To Reproduce Steps to reproduce the behavior:

Apply following Style to Window:

public abstract class MyDialog: Window
{
        static MyDialog()
        {
            // Override default Style
            DefaultStyleKeyProperty.OverrideMetadata(typeof(MyDialog), new FrameworkPropertyMetadata(typeof(MyDialog)));
        }
}
<Style TargetType="{x:Type dialoge:MyDialog}" BasedOn="{StaticResource {x:Type Window}}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type dialoge:MyDialog}">
                <ContentPresenter>
                    <ContentPresenter.LayoutTransform>
                        <ScaleTransform ScaleX="{Binding PRO_dblScale, RelativeSource={RelativeSource AncestorType={x:Type dialoge:MyDialog}}}"
                                        ScaleY="{Binding PRO_dblScale, RelativeSource={RelativeSource AncestorType={x:Type dialoge:MyDialog}}}"/>
                    </ContentPresenter.LayoutTransform>
                </ContentPresenter>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Both drag&drop enabled elements in that Window are ItemControls contained in the same Grid with following ItemPanel A:

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapPanel Style="{StaticResource MyStyle}" />
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

B:

<ItemsPanelTemplate>
    <VirtualizingStackPanel />
</ItemsPanelTemplate>

They have the following set: A:

    dd:DragDrop.IsDragSource="True"
    dd:DragDrop.IsDropTarget="True"
    dd:DragDrop.DragDropCopyKeyState="LeftMouseButton"
    dd:DragDrop.DragAdornerTemplate="{StaticResource MyAdornerTemplateA}"
    dd:DragDrop.DropHandler="{Binding MyDropHandlerA}">

B:

    dd:DragDrop.IsDragSource="True"
    dd:DragDrop.IsDropTarget="True"
    dd:DragDrop.DragAdornerTemplate="{StaticResource MyAdornerTemplateB}"
    dd:DragDrop.DragHandler="{Binding MyDragHandlerB}"
    dd:DragDrop.DropHandler="{Binding MyDropHandlerB}">

Expected behavior DragOver() and Drop() should be called both ways.

Additional Info

Without the override in MyDialogs static constructor drag&drop works as expected. Both in V1.1.0 as in V3.2.1 which is the reason for me suspecting this. If this is not enough to reproduce I'll try to build a demo.

The style is used to couteract DPI-Scaling without actually making the application properly DPI-Aware 😳 It would be a herculean task to do so...

punker76 commented 9 months ago

@G-Huber Please, can you provide a full working sample? You can put it here on GitHub ;-) Thx

FabianOswald-WolfSystem commented 9 months ago

I probably have the same problem. I also use CustomControls and use DefaultStyleKeyProperty.OverrideMetadata. No method is called in my ViewModel.

G-Huber commented 8 months ago

After a whole day of investigation it seems like the issue in 1.1.0 is with DragAdornerTemplates. (Some null pointer exception in the DragAdorner constructor because AdornerLayer.GetAdornerLayer() returns null; Without DragAdorners everything works just fine)

This does not happen in 3.2.1.

The issue I have with 3.2.1 is, that the DropAdorner is way smaller than the item size in my horizontal wrap panel. Minor, but still. Probably not even related to the UI scaling stuff...

G-Huber commented 8 months ago

The adorner displays as expected after changing styles somewhat.

So no issues in regards to UI scaling when using 3.2.1