WPF 目录、文件弹出框

1.System.Windows.Forms

目录选择

     FolderBrowserDialog dialog = new FolderBrowserDialog();
         
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (string.IsNullOrEmpty(dialog.SelectedPath))
                {
                   System.Windows.MessageBox.Show("Click OK");
                  
                }
            }

文件选择

     OpenFileDialog openFileDialog= new OpenFileDialog();
            if (openFileDialog.ShowDialog()== System.Windows.Forms.DialogResult.OK)
            {
               System.Windows.MessageBox.Show("Click OK");
            }

  

 

2.CommonOpenFileDialog

添加WindowsAPICodePack-Shell 的Nuget引用

            CommonOpenFileDialog dialog = new CommonOpenFileDialog();
            dialog.Title = "";
            dialog.AddToMostRecentlyUsedList = false;
            dialog.AllowNonFileSystemItems = false;
            dialog.EnsurePathExists = true;
            dialog.ShowPlacesList = true;
            dialog.IsFolderPicker = true;//True选择文件目录,false选择文件夹
            if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
               
                  System.Windows.MessageBox.Show("Click OK");
            }                

 

posted @ 2019-12-03 16:14  无限环  阅读(614)  评论(0编辑  收藏  举报