} //design time only public SelectFileDialogExampleViewModel(FileAndFolderDialog.Abstractions.IFileDialogService fileDialogService) { this._fileDialogService = fileDialogService; //set defaults var options = new FileAndFolderDialog.Abstractions.OpenFileOptions(); this.AddExtension = options.AddExtension; this.CheckFileExists = options.CheckFileExists; this.CheckPathExists = options.CheckPathExists; this.DefaultExt = options.DefaultExt; this.DereferenceLinks = options.DereferenceLinks; this.Filter = options.Filter; this.FilterIndex = options.FilterIndex; this.InitialDirectory = options.InitialDirectory; this.Multiselect = options.Multiselect; this.ReadOnlyChecked = options.ReadOnlyChecked; this.RestoreDirectory = options.RestoreDirectory; this.ShowReadOnly = options.ShowReadOnly; this.Title = options.Title; this.ValidateNames = options.ValidateNames; this.DefaultFileName = options.DefaultFileName; this.CustomPlaces = new ObservableCollection <string>(); }
/// <summary> /// Executes the ChooseFile command /// </summary> public void ChooseFile() { try { var options = new FileAndFolderDialog.Abstractions.OpenFileOptions() { AddExtension = this.AddExtension, CheckFileExists = this.CheckFileExists, CheckPathExists = this.CheckPathExists, DefaultExt = this.DefaultExt, DereferenceLinks = this.DereferenceLinks, Filter = this.Filter, FilterIndex = this.FilterIndex, InitialDirectory = this.InitialDirectory, Multiselect = this.Multiselect, ReadOnlyChecked = this.ReadOnlyChecked, RestoreDirectory = this.RestoreDirectory, ShowReadOnly = this.ShowReadOnly, Title = this.Title, ValidateNames = this.ValidateNames, DefaultFileName = this.DefaultFileName, }; this.CustomPlaces .ToList() .ForEach(p => options.CustomPlaces.Add(p)); var results = _fileDialogService.ShowSelectFileDialog(options); if (results == null || !results.Any()) { this.SelectionResults = null; } else { this.SelectionResults = string.Join(Environment.NewLine, results); } } catch (Exception ex) { this.SelectionResults = ex.Message; } }