/// <summary> /// 打开一个保存文件的对话框 /// </summary> /// <param name="selectPath">选择的路径</param> /// <param name="fileName">初始化文件名</param> /// <param name="filter">筛选条件</param> /// <returns></returns> public static bool SaveFileDialog(out string selectPath, string fileName = null, string filter = null) { ResourceBrowser browser = new ResourceBrowser(); Window window = null; if (GetWindow != null) { window = GetWindow(ResourceBrowserType.SaveFile); } if (window == null) { window = new Window(); window.WindowStyle = WindowStyle.None; } browser.ResourceBrowserType = ResourceBrowserType.SaveFile; browser.FileFilter = filter; browser.FileName = fileName; window.Content = browser; string result = null; browser.OnOpen += (s, e) => { result = e.FullPaths.FirstOrDefault(); if (!System.Utility.Helper.File.InputPathIsValid(result)) { result = null; XDD.Control.XlyMessageBox.ShowError("请选择的保存路径。"); return; } window.Close(); }; window.ShowDialog(); selectPath = result; return(!selectPath.IsNullOrEmptyOrWhiteSpace()); }
/// <summary> /// 打开一个文件对话框 /// </summary> /// <param name="selectPath">选择的路径</param> /// <param name="filter">筛选条件</param> /// <returns></returns> public static bool OpenFileDialog(out string selectPath, string filter = null) { ResourceBrowser browser = new ResourceBrowser(); Window window = null; if (GetWindow != null) { window = GetWindow(ResourceBrowserType.OpenFile); } if (window == null) { window = new Window(); window.WindowStyle = WindowStyle.None; } browser.ResourceBrowserType = ResourceBrowserType.OpenFile; browser.IsMultipleSelect = false; browser.FileFilter = filter; window.Content = browser; string result = null; browser.OnOpen += (s, e) => { result = e.FullPaths.FirstOrDefault(); window.Close(); }; window.ShowDialog(); selectPath = result; return(!selectPath.IsNullOrEmptyOrWhiteSpace()); }
/// <summary> /// 打开一个文件对话框 /// </summary> /// <param name="selectPaths">选中的文件集合</param> /// <param name="filter">筛选条件</param> /// <returns></returns> public static bool OpenFileDialog(out IEnumerable <string> selectPaths, string filter = null) { ResourceBrowser browser = new ResourceBrowser(); Window window = null; if (GetWindow != null) { window = GetWindow(ResourceBrowserType.OpenFile); } if (window == null) { window = new Window(); window.WindowStyle = WindowStyle.None; } browser.ResourceBrowserType = ResourceBrowserType.OpenFile; browser.IsMultipleSelect = true; browser.FileFilter = filter; window.Content = browser; List <string> result = null; browser.OnOpen += (s, e) => { result = e.FullPaths; window.Close(); }; window.ShowDialog(); selectPaths = result; return(!(result == null || result.Count == 0)); }