简体   繁体   English

Microsoft.Win32.OpenFileDialog 在调试时不显示?

[英]Microsoft.Win32.OpenFileDialog dosn't show while debugging?

I'm building a application on Visual Studio 2015 in C#.我正在 C# 中的 Visual Studio 2015 上构建应用程序。 I'm using Microsoft.Win32.OpenFileDialog to get a file from machine, but while debugging the code stands still at "dlg.showDialog();"我正在使用 Microsoft.Win32.OpenFileDialog 从机器中获取文件,但在调试代码时仍然停留在“dlg.showDialog();” and the dialog box dosn't shown up.并且没有显示对话框。

public static void OpenDialog()
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Title = "ABC";
            dlg.ShowDialog();
        }

Please suggest if there is any other way?请问有没有其他方法?

Microsoft.Win32.OpenFileDialog dosn't show while debugging? Microsoft.Win32.OpenFileDialog 在调试时不显示?

I have tested your code in my side and I did not face the error as you described and I can open the dialog successfully.我已经在我身边测试了你的代码,我没有遇到你描述的错误,我可以成功打开对话框。 So please try these suggestions:所以请尝试以下建议:

1) make sure that your project is a desktop project rather than a console project. 1)确保您的项目是桌面项目而不是控制台项目。

2) reference PresentationFramework.dll under Add Reference-->Reference-->Assemblies-->select PresentationFramework . 2)在 Add Reference-->Reference-->Assemblies-->select PresentationFramework.dll下引用PresentationFramework

3) disable any third party extensions under Tools --> Extensions and Updates to check whether an extension caused this behavior. 3)工具-->扩展和更新下禁用任何第三方扩展,以检查扩展是否导致此行为。

4) then close VS Instance, delete .vs hidden folder under solution folder, bin , obj folder, then restart your project and then test again. 4)然后关闭VS Instance,删除解决方案文件夹, binobj文件夹下的.vs隐藏文件夹,然后重新启动您的项目,然后再次测试。

Then you can set breakpoint to test whether it runs successfully.然后你可以设置断点来测试它是否运行成功。

5) try to create a new project to test these code and if it still does not work, please repair your VS(run the vs2015 installer program and click Repair ). 5)尝试创建一个新项目来测试这些代码,如果仍然无法正常工作,请修复您的VS(运行vs2015安装程序并单击修复)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM