Search code examples
wpfdatagrid

How to move WPF DataGrid Rows using Drag and Drop?


I followed an example from http://www.hardcodet.net/2009/03/moving-data-grid-rows-using-drag-and-drop I am pretty sure I copied all the codes yet strangely I can't see any Drag and Drop effects?

Anyone please have a look at the copied codes? https://www.dropbox.com/sh/e3hgg8kbfjqx21d/AADyTdHQsg1BOcPGePbBnt1ga?dl=0


Solution

  • I analyzed your code and found the issue.

    the issue occurs because you've accidently used System.Windows.Controls instead of Microsoft.Windows.Controls for the reference of DataGridRow used in the following line

    var row = UIHelpers.TryFindFromPoint<DataGridRow>((UIElement)sender, e.GetPosition(shareGrid));
    

    so modify the following reference in MainWindow.xaml.cs

    using System.Windows.Controls;
    

    to

    using Microsoft.Windows.Controls;
    

    Let me know if this helps