WPF文本框不接受输入,空间和退格作品 [英] WPF TextBox doesn't take input, space and backspace works

查看:144
本文介绍了WPF文本框不接受输入,空间和退格作品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件内的文本框,我的用户控件添加到主窗口与下面的XAML代码:

I have textbox inside a usercontrol and I add the usercontrol to the MainWindow with the following XAML:

 <Views:MyUserControl />



我在的MyUserControl一个TextBox,问题是,文本框不接受任何输入。退格OCH空间的作品,但如果我按字母数字OCH没有文本被添加到文本框。

I have one TextBox in MyUserControl, the problem is that the TextBox doesn't take any input. Backspace och space works, but if I press the letter och numbers no text is added to the TextBox.

我已经确定文本不只是隐藏在文本框。
我也试图添加一个RichTextBox具有相同结果的MyUserControl,它好好尝试采取任何输入(空间OCH退格旁)。

I have made sure that the text is not just hidden in the TextBox. I have also tried to add a RichTextBox to MyUserControl with the same result, it doens't take any input (beside space och backspace).

我有也试过一个TextBox添加到具有相同的结果的主窗口;它好好尝试采取任何输入(空间OCH退格旁)。

I have also tried to add a TextBox to the MainWindow with the same result; it doens't take any input (beside space och backspace).

同样是的MyUserControl在一个TabControl和TabItem的补充。

Also MyUserControl is added in a TabControl and TabItem.

任何线索

编辑:更多信息
忘了写,我是开/从一个WinForm应用程序中创建WPF窗口。
当我把我的启动项目,VS10是我的WPF项目它与输入到文本框的键盘工作的伟大。

Additional information Forgot to write that I'm opening/creating the WPF Window from a WinForm application. When I set my startup project in VS10 to be my WPF-project it work great with the keyboard input to the TextBox.

为什么?

林开/创建我的WPF窗口下面的代码:

Im opening/creating my WPF windows with the following code:

MyWpfProject.MainWindow mw = new MyWpfProject.MainWindow();
mw.Show();



编辑:解
所以我想我真正的问题是,就是被打开的WPF项目从WinForms应用程序

Solution So I guess my real problem was that is was opening the WPf project from a WinForms application.

我添加以下代码:

MyWpfProject.MainWindow mw = new MyWpfProject.MainWindow();
ElementHost.EnableModelessKeyboardInterop(mw);
mw.Show();



的EnableModelessKeyboardInterop()如果从非加载呼叫是必要的,以处理在WPF窗口键盘输入-WPF主机一样的WinForms。
的http://博客。 asp.net/jdanforth/archive/2008/07/29/open-a-wpf-window-from-winforms.aspx

推荐答案

答案我自己的问题(如果别人遇到了同样的问题):
如果从一个WinForms应用程序中打开一个WPF的形​​式,你必须做到以下几点,以获取键盘输入:

Answer to my own question (if someone else run into the same problem): If you open a WPF-form from a WinForms application you have to do the following to get keyboard input:

MyWpfProject.MainWindow mw = new MyWpfProject.MainWindow();
ElementHost.EnableModelessKeyboardInterop(mw);
mw.Show();



的EnableModelessKeyboardInterop()如果从非加载呼叫是必要的,以处理在WPF窗口键盘输入-WPF主机一样的WinForms。 http://weblogs.asp.net/ jdanforth /存档/ 2008/07/29 /开-A-WPF窗口 - 从 - winforms.aspx

这篇关于WPF文本框不接受输入,空间和退格作品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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