Giter Club home page Giter Club logo

gong-wpf-dragdrop's Introduction


gong-wpf-dragdrop

GongSolutions.WPF.DragDrop

An easy to use drag'n'drop framework for WPF.

Supporting .NET Framework 4.6.2+, .NET Core 3.1, .NET 5 and .NET 6 (on Windows)


mainstatus devstatus


Features

  • Works with MVVM : the logic for the drag and drop can be placed in a ViewModel. No code needs to be placed in code-behind, instead attached properties are used to bind to a drag handler/drop handler in a ViewModel.
  • Works with multiple selections.
  • Can drag data within the same control to re-order, or between (different) controls.
  • Works with ListBox, ListView, TreeView, DataGrid and any other ItemsControl.
  • Can insert, move or copy an item into a collection of the same/another control (same item type).
  • Can display Adorners to give the user visual feedback of the operation in progress.
  • Can display a preview of the dragged item (the preview is always visible).
  • Has sensible defaults so that you have to write less code for common operations.

Let's get started

License

Copyright ยฉ Jan Karger, Steven Kirk and Contributors. All rights reserved.

GongSolutions.WPF.DragDrop is provided as-is under the BSD 3-Clause License. For more information see LICENSE.

Want to say thanks?

This framework is free and can be used for free, open source and commercial applications. It's tested, used and contributed by many awesome people. So hit the magic โญ button, we appreciate it!!! ๐Ÿ™

Become a sponsor and show your support to this open source project.

If you use GongSolutions.WPF.DragDrop as serious task, and you'd like to honor my work on it, please donate, I'll appreciate it.

Does your company use GongSolutions.WPF.DragDrop? Ask your manager or marketing team if your company would be interested in supporting this project. Your company's logo can be shown on GitHub - who doesn't want a little extra exposure?

In action

gif01

screenshot01

screenshot02

screenshot03

screenshot04

gif02

gong-wpf-dragdrop's People

Contributors

abbottdev avatar arturire avatar asarium avatar berndhaidan avatar chri-s avatar chs499 avatar claudekennilol avatar crazyfox55 avatar dauthleikr avatar deadpikle avatar dependabot[bot] avatar emsaks avatar fraschfn avatar froggiefrog avatar hinidu avatar jizc avatar ltrzesniewski avatar madben2000 avatar metritutus avatar miracle2k avatar mogikan avatar nbusseneau avatar nonlegalarrived avatar punker76 avatar rdingwall avatar readmecritic avatar sm-g avatar thoemmi avatar unitify avatar yohskdista avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gong-wpf-dragdrop's Issues

Null Reference Exception

Original author: [email protected] (May 17, 2012 19:51:46)

In DragDrop.cs

static bool HitTestScrollBar(object sender, MouseButtonEventArgs e)
{
HitTestResult hit = VisualTreeHelper.HitTest((Visual)sender, e.GetPosition((IInputElement)sender));
return hit != null && hit.VisualHit.GetVisualAncestor<System.Windows.Controls.Primitives.ScrollBar>() != null;
}

The HitTestResult was null. I added the 'hit != null &&' to the condition in the return value.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=47

MultiSelection Mode Doesn't Work Well.

Original author: [email protected] (November 08, 2011 14:43:34)

What steps will reproduce the problem?
(I took SchoolsExmaple sample code in Code Project for example.)

  1. Extract SchoolsExample.rar and open project.
  2. add GongSolutions.Wpf.DragDrop.dll in referencs and run it.
  3. check list item.
  4. check checked item again.

Then you can see checking doesn't work.

Hi!
First of all I want to thank you all for your wonderful work.
I try to take you dll for drag and drop but it doesn't work well.
In attached file you can see what is my problem.
When I remove ListBox's SelectionMode="Multiple" then it's a little bit fine.
I think it's because mouse click prblem on list box(which is able to drag and drop)
Help me.
Thank you.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=41

Crash when using items deriving from ContentControl

Original author: [email protected] (December 15, 2011 10:10:19)

What steps will reproduce the problem?

  1. Use a control that derives from ContentControl (Label, Button) for the ItemTemplate in the ItemsControl, like in this example:
<ItemsControl ItemsSource="{Binding Collection}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
                <Label>WhatEver</Label>  
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

What is the expected output? What do you see instead?

  • When you try to drag any item, an exception is thrown.

What version of the product are you using? On what operating system?

  • 1.3, XP

Please provide any additional information below.

It all happens in DragInfo's constructor.
This line fails to retrieve the correct container:
UIElement item = itemsControl.GetItemContainer((UIElement)e.OriginalSource);

Therefore itemParent is null:
ItemsControl itemParent = ItemsControl.ItemsControlFromItemContainer(item);

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=42

Messagebox on listbox previewkeydown problem

Original author: [email protected] (January 12, 2010 04:57:45)

What steps will reproduce the problem?
1.Show a messagebox on the previewkeydown event of the source listbox
2. click the targretlistboxitem shows the messagebox shows somewhere
away from the target listbox
3. click ok and drag from there(the messgabebox position)

Hi,
Just found a little bug i think...I came up with a situation in which i had
to give a message box in my listbox previewkeydown event.What happens is
that,Suppose the Messagebox shows at the centre of the screen..over a plain
border..First i click the listbox(just click no drag) the message is shown
over a border.I click ok and drag from the border..Interesting it
works..and drags the clicked listbox content..

Further drag is no more possible from the target listbox...

Pls help me finding a solution to this.I can provide you a sample code to
reproduce this issue...thanks

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=3

Error with HitTestScrollBar

Original author: [email protected] (April 07, 2011 11:48:11)

There is an issue with the HitTestScrollBar code.

You current have the line:

hit.VisualHit.GetVisualAncestor&lt;System.Windows.Controls.Primitives.ScrollBar&gt;() != null;

This checks to see if the visual ancestor of the hit item is the a scroll bar. However what it doesn't check for is if its visible or not.

I've changed the version in my branch to be:

static bool HitTestScrollBar(object sender, MouseButtonEventArgs e)
{
    HitTestResult hit = VisualTreeHelper.HitTest((Visual)sender, e.GetPosition((IInputElement)sender));

    if (hit == null)
        return false;
    else
    {
        var scrollBar = hit.VisualHit.GetVisualAncestor<System.Windows.Controls.Primitives.ScrollBar>();
        return scrollBar != null && scrollBar.Visibility == Visibility.Visible;
    }
}

Without the extra visibility check the scroll bar is reporting it is being hit when it isn't visible, and therefore stops the user from dragging the item.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=34

How to know the item position when moving

Original author: [email protected] (January 02, 2012 10:20:39)

Let's explain the context. I have a treeview or a list with 3 items. I want to move the last one to above the first item. If I apply the move effect it appears a line that shows me the place I would like to place my item. Depending where I put my mouse pointer on the first item I see that line under or abover that first element.

My question. How can I get that position when I perform the drop action?

Thank you

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=43

Bubbling events

Original author: [email protected] (May 21, 2010 06:45:03)

What steps will reproduce the problem?

  1. Place a droptarget on a Grid
  2. Inside the grid, place a new droptarget on a child element of the grid

Since I'm using MVVM I have a different ViewModel for the child element, thus also a different event handler
for dropping an element of a different type than dropped onto the parent Grid.

What is the expected output? What do you see instead?
The grid will handle the event and the dragOver event will never trigger on the child

What version of the product are you using? On what operating system?
1.1 on WinXP

Please provide any additional information below.

I circumvented this by adding a new property in DragInfo called "IsNotHandled" (inverted to apply default
behaviour in this case)
In the DragDrop class I changed the following code;

static void DropTarget_PreviewDragOver(object sender, DragEventArgs e)
{ 
    ...

    e.Handled = !dropInfo.IsNotHandled; // Allows bubbling
    Scroll((DependencyObject)sender, e);
}

and

static void DropTarget_PreviewDrop(object sender, DragEventArgs e)
{
    ...

    e.Handled = !dropInfo.IsNotHandled; // Allows bubbling
}

In the handler for my Grid I've added the following code:

public void DragOver(DropInfo dropInfo)
{
    if (dropInfo.Data is ButtonLayoutViewModel || dropInfo.Data is JoystickLayoutViewModel)
    {
        dropInfo.DropTargetAdorner = DropTargetAdorners.Highlight;
        dropInfo.Effects = DragDropEffects.Copy;
    }
    else
    {
        dropInfo.IsNotHandled = true; // Allows the event to bubble to the next element
    }
}

This resolved my issue of allowing drop onto a child viewmodel on a viewmodel.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=15

After doublclick, item loose focus

Original author: [email protected] (April 12, 2012 14:28:28)

What steps will reproduce the problem?
Customize the SchoolsExample:

  1. Add a MouseDoubleClick EventHanlder to the ListBox of Pupils
  2. When the MouseDoubleClick, show a messagebox
  3. Close the messagebox -> the doubleclicked item looses the focus and selection

What is the expected output? What do you see instead?
The item should be focused and selected.

What version of the product are you using? On what operating system?
0.1.2 Windows 7

Please provide any additional information below.
To solve this problem, add these lines at the begin of "DragDrop.DragSource_PreviewMouseLeftButtonDown":
...
if (e.ClickCount != 1)
return;
...

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=45

DragSource with extended selection

Original author: [email protected] (April 05, 2010 20:20:37)

What steps will reproduce the problem?

  1. Implement extended selection and IsDragSource on a ListBox

    <ListBox ...
    SelectionMode="Extended"
    dd:DragDrop.IsDragSource="True" />

  2. Select a least two items on the ListBox

  3. On a selected item do a mouse click and release the mouse button.

What is the expected output? What do you see instead?
I expect that only one item was selected.
Instead of these behavior the selection not change.

If you select all items, then you dont have chance to unselect all items.

The selection must change only on MouseUp, otherwise could not do multiple
DragDrop.

What version of the product are you using? On what operating system?

  • Trunk r17. Windows xp sp3

Please provide any additional information below.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=8

IDropTarget methods don't fire if using Gong drap/drop in an AvalonDock floating window

Original author: [email protected] (January 12, 2012 16:43:10)

What steps will reproduce the problem?

  1. Include AvalonDock and Gong DragDrop in a WPF project.
  2. Create an AvalonDock DockingManager with a DockableContent pane.
  3. Drag the DockableContent out as a floating window.
  4. Attempt to drag/drop anything with Gong DragDrop in the floating window.

What is the expected output? What do you see instead?
The IDropTarget methods are never fired.

What version of the product are you using? On what operating system?
GongSolutions.Wpf.DragDrop-0.1.2.zip on Windows 7.

Please provide any additional information below.
To be honest, I'm not sure if this is a Gong problem or AvalonDock problem. Just putting it out there that Gong DragDrop and AvalonDock don't play nice. Note that everything works perfectly in a non-floating (docked) window.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=44

Adorner always visible

Original author: [email protected] (May 27, 2010 08:50:55)

The Adorner is only visible when effects != none AND dragsource does also
accept drops.

I don't know about the window guidelines, but I like that the Adorner is
always visible (even if the source doesn't accept drops).

I did accomplish this in two ways:

  1. Let the source also accept drops. Create a class ListViewDropHandler :
    IDropTarget that always returns Effects.None at dragover
  2. Change DropTarget_PreviewDragOver in dragdrop.cs. Comment the line "if
    (dropInfo.Effects != DragDropEffects.None)" and remove the else part.

I came up with this idea as it is a bit strange that when you start
dragging you only see the "forbidden sign" and when a drag is allowed
you'll see the adorner with the "copy sign".

What do you think about this?

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=16

Drag ListBoxItem that includes a TextBox

Original author: [email protected] (April 11, 2010 22:40:46)

What steps will reproduce the problem?

  1. Create a ListBox (in my case bound to a ObservableCollection in my ViewModel)
  2. Use a DataTemplate that includes a TextBox.

What is the expected output? What do you see instead?
When you try do drag one item, grabbing it within the TextBox, the application stops in CanAcceptData (DefaultDropHandler.cs)
at:
"if (dropInfo.DragInfo.SourceCollection == dropInfo.TargetCollection)"
because dropInfo.DragInfo is null.

What version of the product are you using? On what operating system?
0.1.2

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=9

Handling nested listboxes

Original author: [email protected] (August 10, 2010 21:29:00)

What steps will reproduce the problem?

  1. Use a ListBox that has as items other ListBoxes

I feel the current implementation does not support nested Listboxes :(
Is there a way to accomplish that?

I have something like this:

Parent ListBox
-- PListBoxItem1
-- PListBoxItem2
-- PListBoxItem3
---- Child ListBox
------ Child ListBoxItem1
------ Child ListBoxItem2 -Click drag started here
------ Child ListBoxItem3

The current implementation is always detecting ParentListBox as DragSource...

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=28

Additional nice Features

Original author: [email protected] (February 18, 2010 10:47:53)

Hi

Your Library is great!

I suggest some additional features:

  1. Partial Trust support

The call to System.Windows.DragDrop.DoDragDrop() causes an exception when
used in partial trust (e.g. with XBAP). That means that we have to use
another mechanism for drag&drop. A solution for that can be found here:
http://blogs.claritycon.com/blogs/lee_roth/archive/2009/04/06/wpf-drag-and-
drop-between-itemscontrols.aspx

  1. Jump-Back Animation

The soultion mentioned above
(http://blogs.claritycon.com/blogs/lee_roth/archive/2009/04/06/wpf-drag-
and-drop-between-itemscontrols.aspx) shows a nice effect: the
dragAdorner "jumps" back to the origin if drag-drop operation fails.

  1. Designed as Behavior

With Expression Blend 3 a new kind of customizable code arrived: Behaviors.
Changing the actual frame into a behavior might simplify usage of the code
out of designers. Example:
http://codeblitz.wordpress.com/2009/06/26/wpf-itemscontrol-drag-drop-
behavior/

What do you think about this extensions?

Best Regards,

Linus

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=7

Support for DragNDrop across windows

Original author: [email protected] (July 02, 2010 11:52:23)

What steps will reproduce the problem?

  1. Create two windows with ItemsControls
  2. Try to drag and drop an item from one window to the other

What is the expected output? What do you see instead?
I expected the adorner to appear in the second window, but it isn't.

What version of the product are you using? On what operating system?
0.1.2

Please provide any additional information below.
Hello, first I wanted to say that i like your lib. It is simple and works like a charm. Anyway, in my application I have floating windows with base data in it and I need to drag and drop it to the main area.

But, because you use the "m_DragInfo.VisualSource" to determine the adorner layer, the adorner isn't rendered on the second window (adorned layer of the first window is used).

I have an easy solution for this:

instead of:

static void DropTarget_PreviewDragOver(object sender, DragEventArgs e)
{
...
CreateDragAdorner();
}

you could use the sender of the event to determine the adorner layer:

static void DropTarget_PreviewDragOver(object sender, DragEventArgs e)
{
...
CreateDragAdorner(sender as UIElement);
}

then you need just to use that element to determine the adorner layer:

static void CreateDragAdorner(UIElement sender)
{
...
Window parentWindow = sender.GetVisualAncestor<Window>();
}

For me it works!

What do you think about that?

Thank you,
Cheers,
Andreas

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=23

CreateDragAdorner doesn't use correct rootElement

Original author: [email protected] (May 04, 2010 14:56:40)

When you start dragging and your window isn't the main one, the dragAdorner
isn't shown.

Please change CreateDragAdorner into:
static void CreateDragAdorner()
{
DataTemplate template =
GetDragAdornerTemplate(m_DragInfo.VisualSource);

        if (template != null)
        {
            UIElement rootElement = null;
            // Find the current top window 
            Window parentWindow =

TryFindParent<Window>(m_DragInfo.VisualSource);
if (parentWindow != null)
rootElement = parentWindow.Content as UIElement;
if (rootElement == null)
rootElement =
(UIElement)Application.Current.MainWindow.Content;
UIElement adornment = null;
....

The TryFindParent method is well documented at
http://www.hardcodet.net/2008/02/find-wpf-parent

Good luck,

Frank

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=11

Dragging item onto scroll bar drops item at the bottom

Original author: [email protected] (July 08, 2010 13:16:25)

What steps will reproduce the problem?

  1. Create a list box with IsDragSource="True" and IsDropTarget="True"
  2. Drag and drop a list box item onto the scroll bar

What is the expected output? What do you see instead?
Expected: Drop fails or the cursor changes to show that dropping is not enabled on the scroll bar, no changes to the list.
Reality: Item moved to the bottom of the list.
It looks like the default drop target is the last item in the list. So when the algorithm cannot determine which item is the target, it just drops at the end of the list.

What version of the product are you using? On what operating system?
0.1.2 on Windows XP

Please provide any additional information below.
I am binding the items to the list box

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=25

Compile under VS Express 2010

Original author: [email protected] (July 14, 2010 02:19:05)

Download version 0.1.3 and compile under VS 2010 Express

  1. I had to remove the UnitTest project from the solution as it did not convert correctly to VS 2010.
  2. To compile, I had to add a reference to System.XAML
  3. To compile, I had to delete the tk: tag in front of the DataGrid in the DefaultsExample. I also removed the xmlns line for the tk tag.
  4. To compile, I had to remove the WPFToolkit reference from DefaultsExample.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=27

No support for derived item container classes

Original author: [email protected] (January 16, 2011 15:53:40)

I have a ListBox which uses a custom item container class (derived from ListBoxItem). After enabling drag and drop for this ListBox (using dd:DragSource = "true" dd:DropTarget = "true") selecting any item was not possible anymore.

The problem is caused by, GetItemContainer not finding my custom derived item container class.

I'd recommend changing GetVisualAncestor not to use "==" for type checking, but using something which is comparable to the "is" operator:

public static DependencyObject GetVisualAncestor(this DependencyObject d, Type type)
{
    DependencyObject item = VisualTreeHelper.GetParent(d);

    while (item != null)
    {
        if (item.GetType() == type ||
            item.GetType().IsSubclassOf(type)) 
            return item;
        item = VisualTreeHelper.GetParent(item);
    }

    return null;
}

After this change the problem is gone.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=30

Display drag adorner on none drop target

Original author: [email protected] (February 12, 2010 11:16:17)

What steps will reproduce the problem?

  1. Declare a DragAdornerTemplate on drag source
  2. Drag item onto an area that doesn't support drop
    3.

What is the expected output? What do you see instead?
I'd expect the drag adorner to still be displayed but it doesn't.

What version of the product are you using? On what operating system?
0.1.2

Please provide any additional information below.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=6

Problem with drag n drop when ContextMenu is open

Original author: [email protected] (June 18, 2010 19:06:29)

What steps will reproduce the problem?

  1. Create a ListView (set IsDropTarget=True, IsDragSource=True, DropHandler={Binding}
  2. Set a ContextMenu on the ListView
  3. Open the ContextMenu by rightclicking on an item
  4. Select another item while the ContextMenu is open

What is the expected output? What do you see instead?
I expect the just clicked item to get selected without doing anything.
Instead the Framework thinks that I want to drag the item on which the ContextMenu was opened and therefor calls the Drop-Handler.

What version of the product are you using? On what operating system?
Windows 7, newest Version (just updated)

Please provide any additional information below.
Please check this and my other two issues. Thank you.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=22

Dragging data between two instances of the application causes Invalid tymed (Exception from HRESULT: 0x80040069 (DV_E_TYMED)) exception

Original author: [email protected] (December 07, 2010 14:58:50)

What steps will reproduce the problem?

  1. Implement IDragSource.
  2. Start drag of data (row from wpf datagrid in my case)
  3. Add clone of user-defined data to the IDragInfo.Data object in StartDrag.
  4. Drag over the same datagrid in second instance of application.

What is the expected output? What do you see instead?

The expected output would be the cloned data added to the datagrid. In the DragOver and Drop events I would handle any data issues. However, I never get that far because the Invalid tymed (Exception from HRESULT: 0x80040069 (DV_E_TYMED)) exception is raised by the O/S at line 135 in GongSolutions.Wpf.DragDrop.DropInfo.cs (code is Data = (e.Data.GetDataPresent(dataFormat)) ? e.Data.GetData(dataFormat) : e.Data;).

What version of the product are you using? On what operating system?
0.1.3 (Assembly version) - I built from source
Windows XP

Please provide any additional information below.

Exception details follow:

System.Runtime.InteropServices.COMException was unhandled by user code
Message=Invalid tymed (Exception from HRESULT: 0x80040069 (DV_E_TYMED))
Source=mscorlib
ErrorCode=-2147221399
StackTrace:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at System.Windows.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& formatetc, STGMEDIUM& medium)
at System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& format, STGMEDIUM& medium)
at System.Windows.DataObject.OleConverter.GetDataInner(FORMATETC& formatetc, STGMEDIUM& medium)
at System.Windows.DataObject.OleConverter.GetDataFromOleHGLOBAL(String format, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetDataFromBoundOleDataObject(String format, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert)
at System.Windows.DataObject.GetData(String format, Boolean autoConvert)
at System.Windows.DataObject.GetData(String format)
at GongSolutions.Wpf.DragDrop.DropInfo..ctor(Object sender, DragEventArgs e, DragInfo dragInfo)
at GongSolutions.Wpf.DragDrop.DragDrop.DropTarget_PreviewDragOver(Object sender, DragEventArgs e)
at GongSolutions.Wpf.DragDrop.DragDrop.DropTarget_PreviewDragEnter(Object sender, DragEventArgs e)
at System.Windows.DragEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.OleDropTarget.RaiseDragEvent(RoutedEvent dragEvent, Int32 dragDropKeyStates, Int32& effects, DependencyObject target, Point targetPoint)
at System.Windows.OleDropTarget.MS.Win32.UnsafeNativeMethods.IOleDropTarget.OleDragOver(Int32 dragDropKeyStates, Int64 point, Int32& effects)
InnerException:

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=29

About DragInfo.DragStartPosition - e.GetPosition(null) is misleading when using with Context menu

Original author: [email protected] (April 27, 2011 06:50:20)

I would begin with that, this is a wonderful framework for Drag and Drop in wpf.
Ok, with that said, there was a small issue that I had been facing. I just wanted to report that and also how I resolved it? I was trying this framework with a ListView. My listview control is my DragSource(=True). Incidently, the listview also has its context menu. Now the problem arises when I right-click on an item and then (just to close the context menu) click anywhere (sometimes on one of the items) on the listview. Now when I would click on one of the items, it sets System.Windows.DragDrop.DoDragDrop(,,,), in the DragSource_PreviewMouseMove event handler, even though I had just clicked the left button (not dragged it). It would have been fine otherwise, but in this case it does not fire the PreviewMouseLeftButtonUp event, with the result that my Mouse pointer stops taking any input. I am not able to click on any other button on the window untill I minimize and then maximize the window. Now here is the list of events that could be reason of the problem;
1.I right click on an item in listview to bring-up the Context menu.
2.I donot click on the Context menu item and instead click on some listviewitem again to close the context menu
-here, first PreviewMouseLeftButtonDown is called which is handled by DragSource_PreviewMouseLeftButtonDown
-inside this handler this code, "mDragInfo = new DragInfo(sender, e);" creates mDragInfo
-inside the ctor of mDragInfo, this code, "DragStartPosition = e.GetPosition(null);" sets the DragStartPosition, BUT RELATIVE TO MY CONTEXT MENU
-then, PreviewMouseMove is called which is handled by DragSource_PreviewMouseMove
-here, this code, "Point position = e.GetPosition(null);" takes the position again, BUT THIS TIME RELATIVE TO MY LISTVIEW
-and when it compares the two positions in the code below, it evaluates to True;
if (Math.Abs(position.X - dragStart.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(position.Y - dragStart.Y) > SystemParameters.MinimumVerticalDragDistance)
-and this leads to setting the System.Windows.DragDrop.DoDragDrop(,,,)
which wouldn't have otherwise happened if it would be a simple mouse-click on a list view

To resolve it, I simply took "sender" as argument for the two e.GetPosition() statements (one in the ctor of DragInfo and the other in DragSource_PreviewMouseMove event handler). Since, in my case the sender in context of both the statements was the same listview, so I could get it right.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=35

The Dropped function from IDragSource is called on the target and not the Source

Original author: [email protected] (November 15, 2012 23:44:01)

What steps will reproduce the problem?

  1. Create a ViewModel class A and implement IDragSource
  2. Create a ViewModel class B and implement IDropTarget
  3. Create two ListBox (named LBA and LBB).
  4. Set the datacontext of LBA to a viewModel instance of type A.
  5. Set the datacontext of LBB to a viewmodel instance of type B
  6. Set the IsDragSource and DragHandler to LBA
  7. Set the IsDropTarget and DropHandler to LBB
  8. Try to move items from LBA to LBB

What is the expected output? What do you see instead?
I would like the Dropped function on my view model A to be called when a drop occurs
Instead of the one ine the DefaultDragHandler

What version of the product are you using? On what operating system?
Last one, Windows 7

Please provide any additional information below.

Looking at the code, it seems that the issue came from
file: DragDrop.cs
function: static void DropTarget_PreviewDrop(object sender, DragEventArgs e)
Line: IDragSource dragHandler = GetDragHandler((UIElement)sender) ?? DefaultDragHandler;

We are getting the DragSource of the sender uiElement which is the target one (i.e. LBB)

I fixed it by replacing the line with this one:
IDragSource dragHandler = GetDragHandler(_DragInfo.VisualSource) ?? DefaultDragHandler;

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=49

'System.Windows.Documents.Run' is not a Visual or Visual3D' Exception

Original author: [email protected] (June 04, 2010 12:57:40)

Suddenly an unhandled Exception is thrown namely:
'System.Windows.Documents.Run' is not a Visual or Visual3D'

The exception occurs in
VisualTreeExtensions.cs in the Method GetVisualAncestor<T>(this
DependencyObject d) where T : class

To solve the problem I would add a check like so:
public static T GetVisualAncestor<T>(this DependencyObject d) where T :
class
{
if (d is Visual || d is System.Windows.Media.Media3D.Visual3D)
{
DependencyObject item = VisualTreeHelper.GetParent(d);

    while (item != null)
    {
        T itemAsT = item as T;
        if (itemAsT != null) return itemAsT;
        item = VisualTreeHelper.GetParent(item);
    }
}

return null;

}

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=17

Support for TreeView

Original author: [email protected] (June 04, 2010 13:59:15)

I added a feature to better support the TreeView with the drag and drop.
I wanted to provide you my solution maybe you can integrate it in a future
release:
First I wanted that the treeview items expanded themselves when dragging
over them. For this I added the following code to DropInfo.cs Line 63

TreeViewItem tvItem = item as TreeViewItem;
if (tvItem != null)
{
    tvItem.IsExpanded = true;
}

Then there was a little problem with the Highlight Adorner because it
Highlighted not only the treenode where the mouse was over but also all its
child nodes. Found a solution but it is a bit hacky. Maybe there is a
cleaner solution for this out there. I modified the method OnRender in
DropTargetHighlightAdorner.cs to the following:

protected override void OnRender(DrawingContext drawingContext)
{
    if (DropInfo.VisualTargetItem != null)
    {
        Rect rect;
        TreeViewItem tvItem = DropInfo.VisualTargetItem as TreeViewItem;
        if (tvItem != null)
        {
            var grid = (Grid)((UIElement)VisualTreeHelper.GetChild(DropInfo.VisualTargetItem, 0));
            var descendant = VisualTreeHelper.GetDescendantBounds(DropInfo.VisualTargetItem);

            rect = new Rect(DropInfo.VisualTargetItem.TranslatePoint(new Point(), AdornedElement),
                            new Size(descendant.Width + 4, grid.RowDefinitions[0].ActualHeight));
        }
        else
        {
            rect = new Rect(DropInfo.VisualTargetItem.TranslatePoint(new Point(), AdornedElement),
                            VisualTreeHelper.GetDescendantBounds(DropInfo.VisualTargetItem).Size);
        }

        drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Gray, 2), rect, 2, 2);
    }
}

Anyway. Very nice work. Didn't found anything comparable.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=18

Dragging an element as a child to an empty treeview item does not work

Original author: [email protected] (February 18, 2011 19:21:53)

Dropping a child element into a treeviewitem will not add the element as a child of the treeviewitem.

Take the default sample application, look at the 'bound treeview' window and drag all of the children from one parent to another, then once empty, try to drag one of the children back to the original parent.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=31

Deselect selected ListViewItem?

Original author: [email protected] (June 07, 2010 17:07:43)

What steps will reproduce the problem?

  1. Create a ListView and DataBind ItemsSource-Property.
  2. Set IsDragSource="True"
  3. Select a few Items of the ListView (Ctrl+LeftMouseClick)
  4. Try to deselect/unselect/remove selection from a selected item (Ctrl
    +LeftMouseClick)

What is the expected output? What do you see instead?
I expect the selection of the item to be removed but nothing happens -
selection of items cannot be removed with Ctrl+LeftMouseClick.

What version of the product are you using? On what operating system?
0.1.2 on Windows 7

Please provide any additional information below.
I really like this drag n drop implementation.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=20

Dragging a single item from a grouped datagrid will often return CollectionViewGroupInternal rather than the item

Original author: [email protected] (March 30, 2011 22:46:28)

>What steps will reproduce the problem?

  1. I modified the DefaultsExample by adding a 'DataGrid with Groups' tab bound to the same GroupedCollectionViewSource as in the 'Listbox with groups' tab

>What is the expected output? What do you see instead?
Sometimes it would work as expected as it does in 'Listbox with Groups' but most of the time the dropInfo.Data was a CollectionViewGroupInternal instead of a GroupedItem which caused an exception. Dragging multiple items always worked after I modified Data.Drop.

I suspect the problem maybe the DataGrid itself.

>What version of the product are you using?
Latest from subversion

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=33

Select single item (ListViewItem) from current selection

Original author: [email protected] (June 07, 2010 17:16:02)

What steps will reproduce the problem?

  1. Create a ListView, set IsDragSource="True", set
    SelectionMode="Extended", databind ItemsSource-Property.
  2. Select a few ListViewItems (Ctrl+LeftMouseClick)
  3. Select FIRST selected item (simple LeftMouseClick).

What is the expected output? What do you see instead?
I expect all the selected items to be deselected/unselected and the just
selected item to be selected. Instead nothing happens - all the items
remain selected.

What version of the product are you using? On what operating system?
0.1.2 on Windows 7

Please provide any additional information below.
If another selected item (not the first one we selected) is being simple
clicked (to select it and remove all other selections) it works - anyway
it doesnt work if we try to do that for the FIRST selected item.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=21

mouse clicks not recognized

Original author: [email protected] (February 09, 2010 14:53:09)

What steps will reproduce the problem?

  1. Call Some selection changed events(comboboxes) in the drop event
    2.
    3.

What is the expected output? What do you see instead?
I can see that the drop event is executed twice.Also after the events the
mouse clicks are not recognized any more.If i move the mouse out of the
application(suppose taskbar) then everything works fine.Where has my mouse
clicks gone..?Please give me a solution

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=5

Highlight adorner outlines too much when TreeView item is collapsed

Original author: neilboyd (October 11, 2011 15:12:39)

What steps will reproduce the problem?

  1. Change the DefaultDropHandler to use DropTargetAdorners.Highlight instead of DropTargetAdorners.Insert (an easy way to demonstrate the issue)
  2. Run the DefaultsExample
  3. Select the Bound TreeViews tab
  4. Expand Root1
  5. Collapse Root1
  6. Expand Root2
  7. Drag Item10 over Root1

What is the expected output? What do you see instead?
You will see that the highlight outline covers the space that Root1 did have when it was expanded.
It should only cover the now collapsed space.

What version of the product are you using? On what operating system?
Revision 38. Windows XP.

Please provide any additional information below.
Patch to fix it is attached.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=39

Patch: DragInfofactory

Original author: [email protected] (May 25, 2011 10:14:22)

Linked to issue 26, but with a complete patch.

Not sure what your final plans are.
But we are needing to drag items from controls which are not item controls.
such as DevExpress Grids, Images etc

At the moment the DragInfo was tightly couple to the Drag Source being ItemsControl.

This patch abstracts the creation of DragInfo behind a factory allowing for other IDragInfo to be created.

Factory can be set like the handler via dependency property

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=36

DropPosition

Original author: [email protected] (June 07, 2010 10:06:19)

I need to know the mouse position when the drop takes place. Could you
please add the following code to the control?

All in DropInfo.cs

public DropInfo()
{
...
VisualTarget = sender as UIElement;
if (VisualTarget == null)
return;
DropPosition = e.GetPosition(VisualTarget);

if (sender is ItemsControl)
...
(and change the position part in DropPosition here)
}

And add the following code to end of this class:
/// <summary>
/// Gets the mouse position relative to the VisualTarget
/// </summary>
public Point DropPosition { get; private set; }

Once again thanks,

Frank

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=19

Design question

Original author: [email protected] (May 05, 2010 09:27:51)

Hi Grokys. Looks like its getting busy on the drag and drop front!

Anyway I've been playing around on my branch of the code. One thing that
I've needed to change is the events from the 'Preview' versions to the
standard event version. i.e. Switching the events from tunnelling to
bubbling.

This change means that I can put nest controls that all support drag and
drop. (I think this is also the issue that FreakOnALuis is getting when
using a slider on a draggable element.)

So my question is what was the reason for picking the tunnelling event? So
far I haven't found any issues with making this change but just because I
haven't found anyway doesn't mean there aren't any. Am I missing something?

Thanks,

Jon

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=12

DropInfo is not testable

Original author: [email protected] (September 20, 2012 02:26:51)

What steps will reproduce the problem?

  1. I tried mock DropInfo to test IDropTarget implementation using Moq

var fakeDropInfo = new Mock<DropInfo>();
fakeDropInfo.SetupGet(d => d.Data).Returns(file);
fakeDropInfo.SetupGet(d => d.TargetItem).Returns(targetDataTag);

(dialog as IDropTarget).Drop(fakeDropInfo.Object);

  1. I get the error :

Invalid setup on a non-virtual (overridable in VB) member: d => d.Data

What is the expected output? What do you see instead?

I think the 'DropInfo' class should be testable.
Currently it is not implementing any interface and not marked by virtual.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=48

Code submit: display visual of dragged item instead of using template

Original author: [email protected] (June 28, 2011 17:10:07)

I made a quick modification to the DragDrop.CreateDragAdorner() method so that by default (when an adorner template is not specified), an image is extracted from the dragged item(s) and that is used as the adorner instead.

I'm not sure why this was never added as a feature before, it's so easy to implement...

Here is my modification to that method, plus a new helper method to do the image generation:

static void CreateDragAdorner()
{
    var template = GetDragAdornerTemplate(m_DragInfo.VisualSource);

    // This block was added to create a Data Template on the fly with an image generated
    // from m_DragInfo.VisualSourceItem. -- Chris Bordeman [email protected]
    if (template == null)
    {
        template = new DataTemplate();

        var factory = new FrameworkElementFactory(typeof(Image));

        var bs = CaptureScreen(m_DragInfo.VisualSourceItem);
        factory.SetValue(Image.SourceProperty,  bs);
        if (m_DragInfo.VisualSourceItem is FrameworkElement)
        {
            factory.SetValue(FrameworkElement.WidthProperty,((FrameworkElement) m_DragInfo.VisualSourceItem).ActualWidth);
            factory.SetValue(FrameworkElement.HeightProperty, ((FrameworkElement)m_DragInfo.VisualSourceItem).ActualHeight);
        }
        template.VisualTree = factory;
    }

    // The rest of the code was originally inside an "if (template != null)" 
    // block. -- Chris Bordeman [email protected]

    UIElement rootElement = null;
    Window parentWindow = m_DragInfo.VisualSource.GetVisualAncestor<Window>();
    UIElement adornment = null;

    if (parentWindow != null)
    {
        rootElement = parentWindow.Content as UIElement;
    }
    if (rootElement == null)
    {
        rootElement = (UIElement)Application.Current.MainWindow.Content;
    }

    if (m_DragInfo.Data is IEnumerable && !(m_DragInfo.Data is string))
    {
        if (((IEnumerable)m_DragInfo.Data).Cast<object>().Count() <= 10)
        {
            ItemsControl itemsControl = new ItemsControl();
            itemsControl.ItemsSource = (IEnumerable)m_DragInfo.Data;
            itemsControl.ItemTemplate = template;

            // The ItemsControl doesn't display unless we create a border to contain it.
            // Not quite sure why this is...
            Border border = new Border();
            border.Child = itemsControl;
            adornment = border;
        }
    }
    else
    {
        ContentPresenter contentPresenter = new ContentPresenter();
        contentPresenter.Content = m_DragInfo.Data;
        contentPresenter.ContentTemplate = template;
        adornment = contentPresenter;
    }

    if (adornment != null)
    {
        adornment.Opacity = 0.5;
        DragAdorner = new DragAdorner(rootElement, adornment);
    }
}

// Helper to generate the image - I grabbed this off Google 
// somewhere. -- Chris Bordeman [email protected]
private static BitmapSource CaptureScreen(Visual target, double dpiX = 96.0, double dpiY = 96.0)
{
    if (target == null)
        return null;

    var bounds = VisualTreeHelper.GetDescendantBounds(target);

    var rtb = new RenderTargetBitmap((int)(bounds.Width * dpiX / 96.0),
                                     (int)(bounds.Height * dpiY / 96.0),
                                     dpiX,
                                     dpiY,
                                     PixelFormats.Pbgra32);

    var dv = new DrawingVisual();
    using (var ctx = dv.RenderOpen())
    {
        var vb = new VisualBrush(target);
        ctx.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
    }

    rtb.Render(dv);

    return rtb;
}

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=38

Patch: DragInfo Factory

Original author: [email protected] (July 08, 2010 13:36:34)

Not sure what your final plans are.
But we are needing to drag items from controls which are not item controls.
such as DevExpress Grids, Images etc

At the moment the DragInfo was tightly couple to the Drag Source being ItemsControl.

This patch abstracts the creation of DragInfo behind a factory allowing for other IDragInfo to be created.

Factory can be set like the handler via dependency property

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=26

Slider in list item can't be changed. DD thinks the list item is being dragged.

Original author: [email protected] (June 22, 2011 19:57:42)

What steps will reproduce the problem?

  1. In XAML created a ListBox with a DataTemplate containing a slider
  2. Start to move the slider
  3. DD thinks it dragging the list item (you can see the cursor and adorner)
  4. Slider stops moving because presumeably the listItem is being dragged

What is the expected output? What do you see instead?

  1. Would like to be able move the slider in a draggable list item.

What version of the product are you using? On what operating system?

  1. Win 7
  2. Latest download 0.1.2

Please provide any additional information below.

  1. This problem was indirectly mentioned in issues #10 and #12
  2. This is beautifully implemented especially for MVVM. Would really like to standardize on using it.

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=37

Insertion mark/line

Original author: [email protected] (May 05, 2010 14:19:18)

In DropTargetInsertionAdorner.cs you draw an insertion line where the drop
will take place (when dropped).

I think it is beter to not-draw it when drop is not allowed.

Just change:
protected override void OnRender(DrawingContext drawingContext)
{
if (DropInfo.Effects != DragDropEffects.None)
{
....

Another point is that I want to make use of a TreeView and I think we need
a bit different approach here. There is a distinction between dropping on
an treenode and between nodes. Is it possible to mark (based on a
template?) an item instead of a line in that case? I would suggest a couple
of pixels from the top/left and bottom/right would indicate an insertion
and otherwise a drop on that item. You might ask the DragOver what to do.

What do you think about it?

Frank

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=13

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.