方法一:曲线救国,用 OpenFileDialog

OpenFileDialog openFileDialog = new OpenFileDialog
{
    Multiselect = false,
    Title = "选择新建项目的位置",
    CheckFileExists = false,
    CheckPathExists = true,
    FileName = "Folder Selection"
};
if (openFileDialog.ShowDialog() == true)
{
    ...
}

方法二:使用 WinForms 中的 FolderBrowserDialog

更改项目设置:在 usewpf 下面增加:

<UseWindowsForms>true</UseWindowsForms>
using System;
using System.Windows.Forms;

...

using var dialog = new FolderBrowserDialog
{
    Description = "Time to select a folder",
    UseDescriptionForTitle = true,
    SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
        + Path.DirectorySeparatorChar,
    ShowNewFolderButton = true
};

if (dialog.ShowDialog() == DialogResult.OK)
{
    ...
}
最后修改:2021 年 10 月 04 日 11 : 30 AM
真的不买杯奶茶嘛....qwq