zoukankan      html  css  js  c++  java
  • wpf 选择文件夹

    两种方法

    1

    添加System.Windows.Forms的引用

    System.Windows.Forms.FolderBrowserDialog openFileDialog = new System.Windows.Forms.FolderBrowserDialog(); //选择文件夹
    if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)//注意,此处一定要手动引入System.Window.Forms空间,否则你如果使用默认的DialogResult会发现没有OK属性
    {
    txb_Path2.Text = openFileDialog.SelectedPath;
    }

    2

    在WPF中,使用Microsoft.Win32.OpenFileDialog只能选择文件,FolderBrowserDialog只能用树型的方式选择文件夹,很不好用.

    终于找到一个办法,使用Windows API Code Pack

    在VS里打开Package Manager Console后输入Install-Package WindowsAPICodePack-Shell获取包后

    就可以像这样打开选择文件夹Dialog了:

    using Microsoft.WindowsAPICodePack.Dialogs;

    var dlg = new CommonOpenFileDialog();
    dlg.IsFolderPicker = true;
    dlg.InitialDirectory = currentDirectory;

    if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
    {
    var folder = dlg.FileName;
    }

  • 相关阅读:
    POJ 1995
    POJ 3233
    HDU 2815
    POJ 2417
    POJ 3243
    HDU 3579 线性同余方程组
    HDU 1573
    POJ 2115
    POJ 2891
    HDU 2035 不忍直视的水
  • 原文地址:https://www.cnblogs.com/simadi/p/14417022.html
Copyright © 2011-2022 走看看