本文介绍了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:

但是,据我所知,我的模态窗口已经关闭,甚至在我关闭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窗口中键入TextBoxes.但是,每当我单击Backspace [<-]或[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

我想念什么?

推荐答案

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

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模态窗口阻止输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:14