Exemple #1
0
        public void CancelResultTest()
        {
            var result = FileDialogResult.CancelResult();

            Assert.IsFalse(result.IsValid);
            Assert.IsNull(result.FileName);
            Assert.IsNull(result.GetFullFileName());
        }
Exemple #2
0
        private static FileDialogResult ShowFileDialog(object owner, FileDialog dialog, IEnumerable <FileType> fileTypes,
                                                       FileType defaultFileType, string defaultFileName)
        {
            int filterIndex = fileTypes.ToList().IndexOf(defaultFileType);

            if (filterIndex >= 0)
            {
                dialog.FilterIndex = filterIndex + 1;
            }
            if (!string.IsNullOrEmpty(defaultFileName))
            {
                dialog.FileName = Path.GetFileName(defaultFileName);
                string directory = Path.GetDirectoryName(defaultFileName);
                if (!string.IsNullOrEmpty(directory))
                {
                    dialog.InitialDirectory = directory;
                }
            }

            dialog.Filter = CreateFilter(fileTypes);
            if (dialog.ShowDialog(owner as Window) == true)
            {
                filterIndex = dialog.FilterIndex - 1;
                if (filterIndex >= 0 && filterIndex < fileTypes.Count())
                {
                    defaultFileType = fileTypes.ElementAt(filterIndex);
                }
                else
                {
                    defaultFileType = null;
                }
                return(new FileDialogResult(dialog.FileName, defaultFileType));
            }
            else
            {
                return(FileDialogResult.CancelResult());
            }
        }