WPF 選擇文件夾


效果如圖

使用FolderBrowserDialog

System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
System.Windows.Forms.DialogResult result = dialog.ShowDialog();

if (result == System.Windows.Forms.DialogResult.Cancel)
{
    return;
}
selectFolrderPathTextBlock.Text = dialog.SelectedPath.Trim();

使用FolderBrowserDialog

//引用WindowsAPICodePack
var dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
CommonFileDialogResult result = dialog.ShowDialog();
if (result == CommonFileDialogResult.Ok)
{
    selectFolrderPathTextBlock.Text = dialog.FileName;
}

示例代碼

SelectFolder

參考資料

OpenFileDialog In WPF
C# OPENFILEDIALOG打開文件對話框(詳解)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM