2

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

woelfchen42
  • 419
  • 2
  • 8

1 Answers1

1

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();
V.Leon
  • 546
  • 4
  • 9