This is a migrated thread and some comments may be shown as answers.

[Solved] Grid Crash on Header Tap

1 Answer 91 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Saad
Top achievements
Rank 1
Saad asked on 26 Jun 2013, 10:28 AM
I have registered a DoubleTapped event in the RadGrid. This event is being called on the gridheader's doubleTap as well. Is there a way in the eventhandler for me to check if the call came from the header doubleTap or if it came from an item doubleTap?


The grid also keeps on crashing in this scenario. I am uploading a video and a sample project at the following link which may help you in reproducing the problem.

https://skydrive.live.com/?cid=FBEBE0401C936BCE&id=FBEBE0401C936BCE%21140



Thanks

1 Answer, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 26 Jun 2013, 01:19 PM
Hi Saad,

Thank you for contacting us.

I checked the provided project and video and I must confirm that this is a bug. I have forwarded it to our development team and we will do our best to fix it in the Q2 2013 Service Pack 1 release.
Let me elaborate on the reason that causes it. When the DoubleTapped event is raised, the RadDataGrid loses focus because of the showed MessageBox. At the same moment, the RadDataGrid tries to execute a DragDropOperation on the ColumnHeader, but as the focus is lost, the value of the Pointer is null.
In your scenario, to prevent the execution of the DoubleTapped event handler when the call comes from a ColumnHeader, I can suggest you check if the DoubleTappedRoutedEventArgs.OriginalSource has a parent of type DataGridColumnHeader:

var originalSource = e.OriginalSource;
 if (this.IsColumnHeader(originalSource as DependencyObject))
 {
     return;
 }
where the IsColumnHeader method looks like this:
private bool IsColumnHeader(DependencyObject d)
{
    if (d is DataGridColumnHeader)
    {
        return true;
    }
 
    DependencyObject parent = VisualTreeHelper.GetParent(d);
    while (parent != null)
    {
        if (parent is DataGridColumnHeader)
        {
            return true;
        }
 
        parent = VisualTreeHelper.GetParent(parent);
    }
 
    return false;
}

Also, if you need to show the MessageBox when a DoubleTap event is raised expressly on a cell(item) of the RadDataGrid, I can suggest you take advantage of the CellDoubleTap Command. This would be a more clean and MVVM friendly approach.
For more reference, you can also check the Commands-CellDoubleTapCommand project in our SDK Examples for Grid.

Let me know if this works for you. I have also updated your Telerik points as a token of gratitude for your valuable feedback.

Regards,
Ivaylo Gergov
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Grid for XAML
Asked by
Saad
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Share this question
or