Search code examples
silverlightsilverlight-4.0silverlight-toolkit

Getting the destination Point from ItemDragEventArgs in Silverlight


How does one get the destination point from ItemDragEventArgs? With Microsoft.Windows.DragEventArgs e it is easy: e.GetPosition(<UIElement to which the point is relative to>)

XAML


<toolkit:PanelDragDropTarget AllowDrop="True" ItemDroppedOnTarget="DragAndDrop_ItemDroppedOnTarget">

Code behind


private void DragAndDrop_ItemDroppedOnTarget(object sender, ItemDragEventArgs e)
{
   // how to get the destination Point here??
}

Solution

  • This looks like a hack, but it worked and is pretty accurate:

    
    private Point _releasePoint;
    
    public Grid()
    {
       Grid.MouseLeftButtonUp += new MouseButtonEventHandler(Grid_MouseLeftButtonUp);
    }
    
    void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
       _releasePoint = e.GetPosition(Grid);
    }
    
    private void DragAndDrop_ItemDroppedOnTarget(object sender, ItemDragEventArgs e)
    {
       // fires next and _releasePoint is already set
    }