rodriwasabi / gong-wpf-dragdrop

Automatically exported from code.google.com/p/gong-wpf-dragdrop
0 stars 1 forks source link

Raise DropCompleted / DragCompleted #14

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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 reported on code.google.com by sportfr...@gmail.com on 6 May 2010 at 1:07

GoogleCodeExporter commented 8 years ago
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?

Original comment by gro...@gmail.com on 11 May 2010 at 11:22

GoogleCodeExporter commented 8 years ago
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;
}

Original comment by sportfr...@gmail.com on 12 May 2010 at 4:26

GoogleCodeExporter commented 8 years ago
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.

1. Just before "public static class DragDrop":
   public delegate void DragCompletedEventHandler(object sender, DragCompletedEventArgs e);

2. At the end, as a new class:
public class DragCompletedEventArgs : RoutedEventArgs
    {
        public DragCompletedEventArgs(DragInfo dragInfo)
        {
            this.draginfo = dragInfo;
        }
        public readonly DragInfo draginfo;
    }

3. 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);
            }
        }

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

Original comment by sportfr...@gmail.com on 8 Mar 2011 at 1:36