简体   繁体   中英

WPF TextBox events TextChanged PreviewTextInput do not fire

I have inherited an bigger C# Project from a college (hes gone so I can't ask him anymore). Im on VS2012 + .Net4.6 The first time in this Project I added a WPF Textbox to a nonmodal Window. The problem is: I cant change the text in the TextBox.

What I found out are the following facts:

  • The TextBox is not readonly
  • I can use backspace- and delete key, no key else
  • contextmenu with Paste, Copy an Cut works like expected
  • If I open the window modal, I can change the text in the box
  • If I open den window nonmodal I can catch the events PreviewKeyUp, PreviewKeyDown, KeyUp and KeyDown
  • but I cant catch PreviewTextInput, TextInput (thats normal) and TextChanged.
  • When I create a WPF-Project from the scratch, everything works.

We have an own WPF-Window-Style, but it doesn't matter, if I use this style in the window or not.

Can anybody tell me whats the difference of the behavior of TextBoxes in modal / nonmodal Windows. Could you give me a tip, where I could look for a Modification of the behavior between the FromTheScratchProject and our project? Can I debug the eventhandling somehow?

Thank you a lot

It seems like your project is a mix of WinForms/Win32 and WPF.

If you instantiate your window in following way, your non-modal window will catch the keyboard events correctly:

Window wpfWindow = new Window();
ElementHost.EnableModelessKeyboardInterop(wpfWindow);
wpfWindow.Show();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM