Raise DropCompleted / DragCompleted
punker76 opened this issue · 4 comments
Original author: sportfr...@gmail.com (May 06, 2010 13:07:45)
Is it possible to implement raise events DropCompleted and DragCompleted?
In the args info about the source, target and data, or just DropInfo.
Thanks,
Frank
Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=14
From gro...@gmail.com on May 11, 2010 23:22:57
Is this related to Issue #4: Move only?
Where should DropCompleted and DragCompleted be raised? On the drag source or the drop
target?
My proposed fix to issue #4 is to add a DragCompleted method to the IDragSource
interface which accepts a DropInfo. Would this suffice? What would DropCompleted add
that isn't already present?
From sportfr...@gmail.com on May 12, 2010 16:26:37
No, this has nothing to do with #4.
I want to call a method after a drag is completed in the main application itself, and
not in a seperate class.
Normally a drop/drop event fires a DragDrop event at the end, see
http://msdn.microsoft.com/en-us/library/aa289508%28VS.71%29.aspx. But your component
doesn’t.
This is a hint of what I’m thinking of. Not tested, but copied from something else I
created, I think you should change the treeview in a DependencyObject.
public static readonly RoutedEvent DragCompletedEvent = EventManager.RegisterRoutedEvent(
"DragCompleted",
RoutingStrategy.Bubble,
typeof(RoutedEventHandler),
typeof(TreeViewExtensions)
);
private static void RaiseDragCompleted(System.Windows.Controls.TreeView tree)
{
if (DragCompletedEvent != null)
tree.RaiseEvent(new RoutedEventArgs(DragCompletedEvent, null));
}
And called in:
static void DropTarget_PreviewDrop(object sender, DragEventArgs e)
{
….
RaiseDragCompleted(tree);
e.Handled = true;
}
From sportfr...@gmail.com on March 08, 2011 13:36:40
Hi Steven,
I don't know if you have implemented this already.
I have a LINQ datasource as ItemsSource and converted as List (not an ObservableCollection). After a drop the items are not refreshed. Could you please add the following lines to DragDrop.cs? It will add a new event DropCompleted that will be fired after the drop is completed.
-
Just before "public static class DragDrop":
public delegate void DragCompletedEventHandler(object sender, DragCompletedEventArgs e); -
At the end, as a new class:
public class DragCompletedEventArgs : RoutedEventArgs
{
public DragCompletedEventArgs(DragInfo dragInfo)
{
this.draginfo = dragInfo;
}
public readonly DragInfo draginfo;
} -
After "public static readonly DependencyProperty IsDropTargetProperty =":
public static readonly RoutedEvent DragCompletedEvent = EventManager.RegisterRoutedEvent(
"DragCompleted",
RoutingStrategy.Bubble,
typeof(DragCompletedEventHandler),
typeof(DragDrop)
);// Provide CLR accessors for the event public static void AddDragCompletedHandler(DependencyObject dependencyObject, DragCompletedEventHandler handler) { UIElement element = dependencyObject as UIElement; if (element != null) { element.AddHandler(DragCompletedEvent, handler); } } public static void RemoveDragCompletedHandler(DependencyObject dependencyObject, DragCompletedEventHandler handler) { UIElement element = dependencyObject as UIElement; if (element != null) { element.RemoveHandler(DragCompletedEvent, handler); } }
-
At the end of "static void DropTarget_PreviewDrop(object sender, DragEventArgs e)", just before "e.Handled = true;":
if (DragCompletedEvent != null)
{
DragCompletedEventArgs dragCompletedArgs = new DragCompletedEventArgs(m_DragInfo);
dragCompletedArgs.RoutedEvent = DragCompletedEvent;
m_DragInfo.VisualSource.RaiseEvent(dragCompletedArgs);
}
In my application I then have the following:
private void datagrid_DragCompleted(object sender, DragCompletedEventArgs e)
{
datagrid.Items.Refresh();
}
Once again thank you for this nice component,
Frank
this should be going with the Drop function at IDropTarget