WPF DataGrid: how do I stop auto scrolling when a cell is clicked?

Jan 21, 2010 at 1:16 PM
Edited Jan 21, 2010 at 1:17 PM

Problem:
If my WPF DataGrid is not entirely visible (horizontal & vertical scrollbars are showing) and I click on one of my cells that is partially visible, the grid auto-scrolls to bring that cell into view. I don't want this to happen . I've tried playing around with RequestBringIntoView, like this:

private void DataGrid_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
    e.Handled = true;
}

But that does nothing.

Things I've tried:

  • My cells are custom UserControls; I tried putting an event handler for RequestBringIntoView on all UserControls that make up my cells, and tried handling the event, thinking that maybe I wasn't doing enough by just handling RequestBringIntoView on the DataGrid itself. This did not work.
  • Hosted the DataGrid inside of a ScrollViewer, and handled the ScrollViewer's RequestBringIntoView event. This actually works, and stops the auto-scrolling behavior, but in my case hosting a DataGrid inside of a ScrollViewer is not at all desirable, so I need to come up with a different solution.

I'm not sure how to stop this behavior, any ideas?

 


Edit: someone suggested this solution to me, but I was unable to get that to work.