WPF TextBox事件TextChanged PreviewTextInput不会触发 [英] WPF TextBox events TextChanged PreviewTextInput do not fire

查看:152
本文介绍了WPF TextBox事件TextChanged PreviewTextInput不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从一所大学继承了一个更大的C#项目(不见了,所以我再也不能问他了).我在VS2012 + .Net4.6上在该项目中,我第一次将WPF文本框添加到非模式窗口.问题是:我无法更改文本框中的文本.

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.

我发现以下事实:

  • 文本框不是只读的
  • 我可以使用退格键和Delete键,没有其他键
  • 带有粘贴的上下文菜单,复制剪切的效果与预期的一样
  • 如果我打开窗口模式,可以在框中更改文本
  • 如果我以非模式打开书房窗口,我可以捕获事件PreviewKeyUp,PreviewKeyDown,KeyUp和KeyDown
  • 但是我无法捕获PreviewTextInput,TextInput(正常)和TextChanged.
  • 当我从头开始创建WPF项目时,一切正常.

我们有自己的WPF-Window-Style,但这无关紧要,无论我是否在窗口中使用此样式.

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

有人可以告诉我在模态/非模态Windows中TextBoxes的行为有何不同.您能否给我一个提示,在这里我可以寻找FromTheScratchProject和我们的项目之间行为的修改?我可以以某种方式调试事件处理吗?

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?

非常感谢

推荐答案

似乎您的项目是WinForms/Win32和WPF的混合.

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();

这篇关于WPF TextBox事件TextChanged PreviewTextInput不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆