Skip to content

Commit

Permalink
Add hook in drag handler to handle exceptions occurred when data is d…
Browse files Browse the repository at this point in the history
…ropped.
  • Loading branch information
Antonyo committed Aug 7, 2015
1 parent 4ab1b12 commit fba7375
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Examples/DefaultsExample/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public virtual void Dropped(IDropInfo dropInfo)
public virtual void DragCancelled()
{
}


public bool ExceptionOccurred(Exception ex)
{
return false;
}
}

internal class Data : IDropTarget
Expand Down
6 changes: 6 additions & 0 deletions GongSolutions.Wpf.DragDrop/DefaultDragHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ public virtual void Dropped(IDropInfo dropInfo)
public virtual void DragCancelled()
{
}


public virtual bool ExceptionOccurred(System.Exception ex)
{
return false;
}
}
}
5 changes: 5 additions & 0 deletions GongSolutions.Wpf.DragDrop/DragDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,11 @@ private static void DragSource_PreviewMouseMove(object sender, MouseEventArgs e)
if (result == DragDropEffects.None)
dragHandler.DragCancelled();
}
catch (Exception ex)
{
if (!dragHandler.ExceptionOccurred(ex))
throw;
}
finally {
m_DragInProgress = false;
}
Expand Down
12 changes: 12 additions & 0 deletions GongSolutions.Wpf.DragDrop/IDragSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,17 @@ public interface IDragSource
/// Notifies the drag handler that a drag has been aborted.
/// </summary>
void DragCancelled();

/// <summary>
/// Notifies that an exception has occurred upon dragging.
/// </summary>
/// <param name="ex">
/// The exception that occurrred.
/// </param>
/// <returns>
/// Boolean indicating whether the exception is handled in the drag handler.
/// False will rethrow the exception.
/// </returns>
bool ExceptionOccurred(Exception ex);
}
}

0 comments on commit fba7375

Please sign in to comment.