WPF DataGrid MouseMove HitTest etc

Sep 29, 2008 at 9:53 PM
Hi,

Do you know a way to get the DataContext of the currently moused over datarow in the data grid?

I looked at possibly doing a hit test but it was not clear on how I could obtain a reference to a row or grid cell from this.

Thanks,
Jon
Sep 29, 2008 at 10:19 PM

This seemed to do the trick...

        private void Grid_MouseMove(object sender, MouseEventArgs e)
        {
            FrameworkElement element = Grid.InputHitTest(e.GetPosition(Grid)) as FrameworkElement;
            if (element != null)
            {
                SomeEntity ent = element.DataContext as SomeEntity;
            }
}

Any issues with that impl?

Thanks,
Jon