WPF 模态 window in Visual Studio 扩展阻止输入

WPF modal window in Visual Studio Extension blocking input

使用以下 tutorial,在 VSIX 项目中,我创建了一个继承自 Microsoft.VisualStudio.PlatformUI.DialogWindow 的 WPF window,并使用以下代码以模式方式显示它:

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

当我在 RELEASE 模式下编译它并且在没有调试 [Ctrl+F5] 的情况下启动时,它会打开 Visual Studio 的实验版本。在这里,我打开另一个解决方案,然后执行我的模态 Window。 window 工作正常 - 我可以在文本框等中输入

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

此外,当我尝试关闭 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?

但是,据我所知,我的模式 window 已经关闭,甚至在我关闭 Visual Studio.[=17 的这个实例时甚至可能已经被垃圾回收了=]

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

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

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

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

我错过了什么?

发现以下建议 here 似乎对我有用:

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

uiShell.EnableModeless(0);

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

uiShell.EnableModeless(1);