protected override void Execute(BitmapImplementationViewModel parameter) { var bitmapFileOptions = this.bitmapFileOptions.Value; var defaultOption = (BitmapFileOption)setting.GetResolvedValue(); var dialog = new SaveFileDialog { Title = "Save bitmap", Filter = string.Join("|", bitmapFileOptions.Values.Select(bfo => $"{bfo.Name}|*{bfo.Extension}")), OverwritePrompt = true, ValidateNames = true, CheckPathExists = true, CheckFileExists = false, FilterIndex = bitmapFileOptions.Values.TakeWhile(bfo => bfo != defaultOption).Count() + 1, DefaultExt = defaultOption.Extension, InitialDirectory = lastDirectory, DereferenceLinks = true, }; if (dialog.ShowDialog() == true) { var extension = System.IO.Path.GetExtension(dialog.FileName); var encoder = bitmapFileOptions.Values.FirstOrDefault(bfo => bfo.Extension == extension) ?? defaultOption; parameter.Model.GetImage().Save(dialog.FileName, encoder.CreateEncoder()); lastDirectory = System.IO.Path.GetDirectoryName(dialog.FileName); } }
protected override void Execute(BitmapImplementationViewModel parameter) { var option = (BitmapFileOption)setting.GetResolvedValue(); var fileName = tempManager.Value.GetNewFileName(option.Extension); parameter.Model.GetImage().Save(fileName, option.CreateEncoder()); var dataObject = new DataObject(); DataObjectExtensions.SetLinkedWClipboardId(dataObject, parameter.Model.ClipboardObject.Id); dataObject.SetFileDropList(fileName); Clipboard.SetDataObject(dataObject); }