コード例 #1
0
        public string BrowseDestination(Window owner, string destination, string extension)
        {
            using (var dialog = new FileSaveDialog())
            {
                GetFilePathInfo(destination, out var folderPath, out var fileName, out var fileExtension);

                dialog.SetClientGuid(new Guid("486640B6-B311-4EFD-A15F-616F51FAAF5B"));
                dialog.SetDefaultFolder(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
                dialog.SetTitle("Destination file of the image to be created");
                dialog.SetOkButtonLabel("Select");
                dialog.SetCancelButtonLabel("Cancel");
                dialog.SetFileNameLabel("Destination file :");
                dialog.SetDefaultExtension(extension.Substring(1));
                dialog.SetFileTypes($"Image files (*{extension})|*{extension}|All files (*.*)|*.*");
                dialog.SetFileTypeIndex(fileExtension == null || fileExtension.Equals(extension, StringComparison.OrdinalIgnoreCase) ? 1 : 2);
                dialog.DontAddToRecent = true;

                if (fileName != null)
                {
                    dialog.SetFileName(fileName);
                }

                if (PathHelper.DirectoryExists(folderPath))
                {
                    dialog.SetFolder(folderPath);
                }

                return(dialog.ShowDialog(owner) == true?dialog.GetResult() : null);
            }
        }