WPF 窗口文本框 - 编辑文本影响不同的窗口 [英] WPF window textbox - editing text affects different window

查看:38
本文介绍了WPF 窗口文本框 - 编辑文本影响不同的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我们的开发团队编写 Visual Studio 扩展(VSIX 解决方案).当用户激活扩展程序时,他们会得到一个表单,它是一个非常简单的 WPF 窗口.使用以下代码加载窗口:

I am writing a Visual Studio extension for our Dev team (a VSIX solution). When the user activates the extension, they get a form which is a very simple WPF window. The window is loaded using the following code:

var myWindow = new SomeWpfWindow(myArgs)
{
    Owner = Application.Current.MainWindow
};
myWindow.Show();

这将打开并显示用户填写的表单.该表单有许多文本框,它们经历了与 DataContext 的双向绑定.没什么特别的.

This opens and displays a form that the user fills in. The form has lots of TextBoxes that undergo 2-way binding to the DataContext. Nothing too out of the ordinary.

好吧,除了 TextBox 的行为......

Well, apart from the TextBox behaviour....

当我在文本框中输入字符(blah blah blah")时,我看到这些字符显示在文本框中,并且它们也被写入到它们绑定的 DataContext 属性中.

When I type characters in the textbox ("blah blah blah") then I see these characters displayed in the text box, and they also get written to the DataContext property that they're bound to.

不过.当我按下退格或删除按钮时,TextBox 中的文本保持不变,但后面的窗口(在本例中为活动代码文件)被编辑.不理想的行为....

However. When I press the back-space or delete button, then the text in the TextBox remains unchanged, but instead the window behind (in this case, the active code file) is edited. Not ideal behaviour....

我使用 .ShowDialog() 而不是 .Show() 解决了这个问题,但这是正确的解决方法,还是我只是在掩饰问题?

I fixed this by using .ShowDialog() rather than .Show(), but is is the correct fix, or am I just burying the problem?

谢谢

推荐答案

上面提供的解决方案解决了上述问题,但并不是完整的解决方案.我发现,关闭我的 WPF 对话框窗口后,我可以在打开的解决方案中输入 C# 窗口,但无法删除或退格来删除文本.此外,当我尝试关闭 Visual Studio 时,它给出了以下警告:

The solution provided above solved the problem described above, but it wasn't the complete solution. What I found was that, having closed my WPF Dialog Window, I was then able to type into a C# window in the open Solution, but not able to Delete or back-space to remove text. Also when I tried to close Visual Studio, it gave the following warning:

Microsoft Visual Studio 检测到某个操作被阻止用户输入.这可能是由活动的模态对话框或任务引起的需要阻止用户交互.你想关闭吗无论如何?

Microsoft Visual Studio has detected that an operation is blocking user input. This can be caused by an active modal dialog or a task that needs to block user interaction. Would you like to shut down anyway?

请参阅以下帖子以获取解决方案:Visual Studio 扩展中的 WPF 模式窗口阻止输入

Please refer to the following post for the solution to this: WPF modal window in Visual Studio Extension blocking input

这篇关于WPF 窗口文本框 - 编辑文本影响不同的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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