开发者

an enter key are handled twice in WPF/Winform mixed project

开发者 https://www.devze.com 2023-02-03 11:17 出处:网络
I have a winform dashboard which hosts some WPF dialogs. When I select a row in the winform ListView and hit Enter key, OnItemActivate is called which launches a WPF dialog. However, the WPF dialog ap

I have a winform dashboard which hosts some WPF dialogs. When I select a row in the winform ListView and hit Enter key, OnItemActivate is called which launches a WPF dialog. However, the WPF dialog appears and then disappears immediately because the default button “cancel” is hit. It seems that the Enter key is triggered twice, one for launching the WPF dialog, the other for hitting cancel button. We don’t want the WPF dialog to be canceled by the Enter key hitting.

A开发者_Go百科ccording to the stack trace, it looks like that WPF and Winform handle the enter key separately. The WPF does not know that the enter key has been handled by the Winform ListView. Is this by design in Winform and WPF interop?

To make the enter key not close the WPF dialog, we have to change the focus from the cancel button to another control (e.g. a textblock). Is there a better way to fix/around this issue?


As Rick suggested in the comments, try calling Application.DoEvents() before opening the WPF dialog.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号