The grid's mousedoubleclick fires no matter where the user double clicks including headers and the scroll bar.
How can I properly detect that they've only double clicked on a row?
Hello,
What you can do is to use the EventManager.RegisterClassHandler and register this event only for the DataRecordPresenter or create a style for the DataRecordPresenter/ DataRecordCellArea element and use an EventSetter to hook up this event.
Thanks but without sample code to get to the "DataRecordPresenter" this wasn't helpful at all. I finally got a working solution using some techniques from this post:
http://community.infragistics.com/forums/p/7652/96199.aspx#96199
I am not sure how my post was not helpful at all. If you register the event for the DataRecordPresenter, then the Sender will be the DataRecordPresenter itself. You do not need to walk the element tree up and down to find it.
Please note that neither the EventManager class or EventSetter are Infragistics related. If you need assistance on how to use them, you can try these links:
EventManager
EventSetter
How about posting some sample code? I have a this.DataGrid available to me. How do I register an event on the DataRecordPresenter?
Option 1 : EventManager.RegisterClassHandler(typeof(DataRecordPresenter), DataRecordPresenter.PreviewMouseDoubleClickEvent, new MouseButtonEventHandler(OnPreviewMouseDoubleClick));
private void OnPreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
MessageBox.Show((sender as DataRecordPresenter).ToString());
}
Thank You!!
Unfortunately, your example is still trapping double clicks on the column headers.
As Alex explianed It seems like that the best option is to check in the handler of the event whether the sender is header record, by using the IsHeaderRecord Property, and if it is not execute your code.
Hope this helps you.
Any solution for this with all the changes in XAML itself? I am using MVVM.
Is there anyway to do this all in XAML? I am attempting to avoid any code-behind as I am using MVVM. I have it working with the Style option you posted, but it is still calling the event when you double-click the header. Any suggestions for a XAML-only solution?
The EventManager will register this event for all instances of that class. You could check which XamDataGrid is currently invoking this event through the DataRecordPresenter.DataPresenter property and not handle or handle it appropriately.
If that is not an option, then you should use Option 2, which uses a style. The style will register this event only for the instances that it applies to. Therefore, you could put this style in a particular XamDataGrid's Resources and it will apply only for its DataRecordPresenters.
One more problem. The way you are registering the event, it's getting registered statically. I had placed this in my constructor. But then when I have multiple grids on the screen, it fires over and over again for each instance of a grid. So I can't register it in the constructor. How do I register that event but only for the grids I want to?