【问题标题】:in wpf, how can I use a standard dialog to select a directory在 wpf 中,如何使用标准对话框来选择目录
【发布时间】:2011-11-09 11:54:44
【问题描述】:

我需要用户选择一个目录,而不是一个文件。如何使用 Microsoft.Win32.OpenFileDialog(或任何其他组件)来做到这一点?

我在 VisualStudio 2010 (.net 4.0) 中使用 WPF4.0

【问题讨论】:

    标签: .net wpf visual-studio-2010


    【解决方案1】:

    使用 System.Windows.Forms.FolderBrowserDialog :

    var dlg = new System.Windows.Forms.FolderBrowserDialog();
    dlg.ShowNewFolderButton = true; //if you want new folders as well
    dlg.SelectedPath = someStartPath; //where to start
    if( dlg.ShowDialog() == DialogResult.OK )
    {
      //ok user selected something
      DoStuffWith( dlg.SelectedPath );
    }
    

    【讨论】:

      【解决方案2】:

      您可以通过Windows API Code Pack 访问 Win32 生态系统中的许多其他标准对话框和控件。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-02
        • 1970-01-01
        • 2011-11-27
        • 2014-04-28
        • 1970-01-01
        • 2020-12-27
        • 2012-08-15
        • 2022-10-24
        相关资源
        最近更新 更多