private void NewImage_Click(object sender, RoutedEventArgs e) { var cbm = this.CbmFile; if (cbm == null) { return; } this.RunBusyAction(disp => { var image = new CbmImage(); cbm.Images.Add(image); disp(() => this.CbmFile = this.CbmFile); disp(() => this.ImagesList.SelectedIndex = this.ImagesList.Items.Count - 1); }); }
private void AddImage_Click(object sender, RoutedEventArgs e) { var cbm = this.CbmFile; if (cbm == null) { return; } var dialog = new OpenFileDialog(); dialog.CheckFileExists = true; dialog.DefaultExt = ".png"; dialog.Filter = "Images (*.png, *.bmp, *.jpg)|*.png;*.bmp;*.jpg|PNG files (*.png)|*.png|BMP files (*.bmp)|*.bmp|JPG files (*.jpg)|*.jpg"; string fileName; if (dialog.ShowDialog(this) == true) { fileName = dialog.FileName; } else { return; } this.RunBusyAction(disp => { try { var image = CbmImage.FromFile(fileName); cbm.Images.Add(image); disp(() => this.CbmFile = this.CbmFile); disp(() => this.ImagesList.SelectedIndex = this.ImagesList.Items.Count - 1); } catch (Exception ex) { disp(() => MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error)); } }); }