1
votes

I want to display a custom confirmation message box (ChildWindow) when the user selects a row in a DataGrid in Silverlight. The message box simply has 2 buttons, a yes and a no. When the user clicks No, I want to restore the previously selected item in the DataGrid. I have been able to accomplish all of that.

The problem is that when the message box appears and I click NO and I restore the previously selected item, the item that the user tried to select remains in the MouseOver visual state until I move the mouse over some other row.

Is there any known workaround for this unusual behaviour of the DataGrid, or is this perhaps a legitimate bug in the control? I have done my research and I have not found anything as yet.

Any help would be appreciated.

Thanks!

1

1 Answers

0
votes

This is classic mouse enter/leave gotcha thats common in many areas of Silverlight and indeed in many other frameworks as well. The assumption is that that mouse in and out events will come in pairs but they don't when a something else hijacks the mouse events.

Thats is what is happening here the DataGridRow is simplisticly tracking mouse over using the standard mouse events. However when you show a child window while it is in the mouse over state not further mouse events go to the row. When you dismiss the childwindow the mouse is already outside the row so it still gets no events.

A possible workaround is to fiddle with the visual state of the row yourself before showing the child window:-

VisualStateManager.GotoState(someRow, "NormalSelected", false);

Not perfect but possible good enough.