Why is my WPF textbox “kinda” readonly?

后端 未结 5 692
傲寒
傲寒 2020-12-13 14:21

I have a text box in WPF that is part of a datatemplate for a listbox. In that text box I can delete, backspace, spacebar, but I can NOT type in new words, letters or number

5条回答
  •  情深已故
    2020-12-13 15:14

    I was encountering a problem very similar to this. After doing a little research, I found a similar problem listed in MSDN:

    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c68d5f3c-c8cc-427d-82e3-6135d075a304/

    According to the answer to the post, the problem has to do with WPF and WinForms having two very different ways of handling text input. Fortunately, the post listed above gives the following solution:

    When launching the window, use ElementHost.EnableModelessKeyboardInterop(window1). Note that this is a static method - you do not have to instantiate the ElementHost class.

    For example,

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

    This solved the problem for me. Hope this helps.

提交回复
热议问题