WPF TextBox not accepting Input when in ElementHost in Window Forms

前端 未结 4 977
北海茫月
北海茫月 2020-12-05 00:45

We are developing a UI Control in WPF to be consumed within an existing Windows Forms / MFC application engine (Rhino 3D).

The application engine exposes the ability

4条回答
  •  借酒劲吻你
    2020-12-05 01:35

    I have a similar issue with a wxWidgets parent window and embedded WPF TextBox controls. I found that although attaching ChildHwndSourceHook does solve the problem of not receiving keyboard input, I ended up with occasional duplicate space characters. It seems the WM_KEYDOWN message handles the space characters reliably, but a duplicate WM_CHAR message is also received for some of the spaces. To solve this I added the following clause to the body of the ChildHwndSourceHook function, which simply ignores the WM_CHAR space character:

            const UInt32 WM_CHAR = 0x0102;
    
            if (msg == WM_CHAR)
            {
                // avoid duplicated spaces when parent window is a native window
                if (wParam.ToInt32() == 32)
                    handled = true;
            }
    

提交回复
热议问题