Hello,
we have an issue only on Touch screens recognized, that when a new XAML Window is shown, in the XamDataGrid.PreviewMouseLeftButtonDown event.
When in this event, a window is shown, that window doesn't receive any clicks anymore. After clicking multiply times on that new modal window, at some time, that windows receives the focus event again.
Version: 20.1.20201.153
Attached is the sample project.
WpfTouchIssueTest.zip
Hello Bin,
In order to ensure that a data row was clicked, I would recommend handling both the PreviewMouseLeftButtonUp and PreviewMouseLeftButtonDown events. In the PreviewMouseLeftButtonDown event, you can cache the DataRecordPresenter element in a variable that is accessible to both event handlers. Then, in PreviewMouseLeftButtonUp, you can check that variable and set it back to null so that the process can begin again for a different clicked row.
Please let me know if you have any other questions or concerns on this matter.
When I use the ActveDataItem, it also shows my dialog when the user clicks somewhere in the grid. I just want to show my dialog, when the user clicks on the data row. How can I do that?
When you click an item, it will become the “active” item on mouse down, and so by the time the PreviewMouseLeftButtonUp event fires, the ActiveDataItem property on the XamDataGrid will be updated. You can use that to get the item of the clicked row.
Thanks, the Up event is working. But then I cannot receive the selected Row anymore. The following code returns null:
DataRecordPresenter drp = Infragistics.Windows.Utilities.GetAncestorFromType(source, typeof(DataRecordPresenter), true) as DataRecordPresenter; if (drp == null) return; SystemStateLogItem logItem = drp.DataRecord.DataItem as SystemStateLogItem;
Is there maybe an more elegant way to get the item of the clicked row?
My team and I have done an initial review of this support case, and unfortunately none of us have a touch-screen display to reliably test this, but looking at your code, I do have some recommendations that may help.
My first recommendation is to open your new dialog in the PreviewMouseLeftButtonUp event. The preview mouse events can cause some weird behavior when they are opening modal dialogs, and this is not something that is Infragistics-specific. This can be seen when opening a MessageBox in a PreviewMouseDown event. Depending on the control that is handling the PreviewMouseDown event, this can cause issues.
Another recommendation that I have that may help is to wrap your code that opens the modal dialog within a Dispatcher.BeginInvoke action, like so:
Dispatcher.BeginInvoke(new Action(() => { //your code for opening dialog here }), System.Windows.Threading.DispatcherPriority.ApplicationIdle);
This will give your application a little bit of extra time to finish the focus-related actions that happen as a result of the PreviewMouseLeftButtonDown and Up events. I would be curious to know if either of these recommendations resolve the issue you are seeing.