本文介绍了Visual Studio Extension 中的 WPF 模式窗口阻止输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 VSIX 项目中使用以下 教程,我创建了一个继承自 Microsoft.VisualStudio.PlatformUI.DialogWindow 的 WPF 窗口,我使用以下代码以模态方式显示此窗口:

Using the following tutorial, within a VSIX project, I created a WPF window that inherits from Microsoft.VisualStudio.PlatformUI.DialogWindow, and I display this modally using the following code:

var myWindow = new MyWindow(myParameters);
myWindow.ShowDialog();

当我在 RELEASE 模式下编译它并在不调试 [Ctrl+F5] 的情况下启动时,它会打开 Visual Studio 的实验版本.在这里,我打开另一个解决方案,然后执行我的模态窗口.窗口工作得很好——我可以输入文本框等等.

When I compile this in RELEASE mode and start without debugging [Ctrl+F5], it opens the Experimental version of Visual Studio. Here, I open another Solution and then execute my Modal Window. The window works just fine - I can type in text boxes etc, etc.

但是,当我关闭模式对话框窗口 [使用 this.Close()] 时,问题就开始了.如果我导航到打开的解决方案中的一个文档,我可以输入,但键盘按钮退格 [<-] 和 [Delete](可能还有其他)被简单地忽略......我无法删除什么我刚刚打字!

However, when I close the modal dialog window [using this.Close()], the problems start. If I navigate to one of the documents in the open solution, I can type, but the keyboard buttons backspace [<-] and [Delete] (and possibly others too) are simply ignored....I can't delete what I've just typed!

另外,当我尝试关闭 Visual Studio 的这个实验版本时,我收到以下消息:

Also, when I try to close this experimental version of Visual Studio, I get the following message:

Microsoft Visual Studio 检测到某个操作正在阻塞用户输入.这可能是由活动的模式对话框或任务引起的这需要阻止用户交互.你想关机吗还是?

但是,据我所知,我的模态窗口已经关闭,甚至在我关闭这个 Visual Studio 实例时可能已经被垃圾回收了.

But, as far as I can tell, my modal window has been closed and may even have been garbage collected by the time I get to close this instance of Visual Studio.

这不仅限于实验版本 - 当我将此 VSIX 推送到我们的本地库并作为扩展安装时,我会得到相同的行为.

This isn't limited to the Experimental version - when I push this VSIX to our local gallery and install as an Extension, then I get the same behaviour.

我也尝试过明确设置所有者,但他对这个问题没有影响:

I have also tried explicitly setting the owner, but his had no effect on this problem:

var myWindow = new MyWindow(myParameters)
{
    Owner = Application.Curent.MainWindow
}
myWindow.ShowDialog();

如果我将其设为非模态窗口,则会遇到不同(但相关)的问题.在这里,如果我打开 Visual Studio 的实验版本并打开另一个解决方案,我在其中导航到 C# 页面.然后我打开我的扩展程序的 WPF 窗口,我可以在该 WPF 窗口中愉快地输入文本框.但是,每当我单击退格 [<-] 或 [delete] 键时,这不会影响当前的 WPF 文本框,但会影响当前解决方案中先前打开的 C# 代码窗口.请参阅以前的帖子

If I make this a non-modal window, then I get different (but related) problems. Here, if I open the Experimental version of Visual Studio and open the other Solution where I navigate to a C# page. I then open my Extension's WPF window where I can happily type into TextBoxes in that WPF window. However, whenever I click the backspace [<-] or the [delete] keys, this doesn't affect the current WPF textbox but the previously opened C# code window in the current solution. See a previous post on this

我错过了什么?

推荐答案

找到以下建议here 似乎对我有用:

The following suggestion found here seems to work for me:

IVsUIShell uiShell = (IVsUIShell)ServiceProvider.GetService(typeof(SVsUIShell));

uiShell.EnableModeless(0);

var myWindow = new MyWindow(myParameters)
{
    Owner = Application.Curent.MainWindow
}
myWindow.ShowDialog();

uiShell.EnableModeless(1);

这篇关于Visual Studio Extension 中的 WPF 模式窗口阻止输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 09:42