private void MenuItem_Open_Executed(object sender, ExecutedRoutedEventArgs e) { if (!this.imageCanvas.lastChangeSaved) { MessageBoxResult res = MessageBox.Show("Сохранить текущее изображение?", "Внимание", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes); if (res == MessageBoxResult.Yes) { if (ApplicationCommands.Save.CanExecute(null, this)) { ApplicationCommands.Save.Execute(null, this); } else { ApplicationCommands.SaveAs.Execute(null, this); } } else if (res == MessageBoxResult.Cancel) { e.Handled = true; return; } } OpenFileDialog _OpenFile_dlg = new OpenFileDialog(); _OpenFile_dlg.AddExtension = true; _OpenFile_dlg.Filter = "Все типы изображений (*.bmp, *.gif, *.jpg, *.jpeg, *.jpe, *.jfif, *.png, *.tif, *.tiff, *.wdp, *wmp, *hdp, *.tga, *.dds)|*.bmp;*.gif;*.jpg;*.jpeg;*.jpe;*.jfif;*.png;*.tif;*.tiff;*wdp;*wmp;*hdp;*.tga;*.dds"; _OpenFile_dlg.Filter += "|BMP (*.bmp)|*.bmp"; _OpenFile_dlg.Filter += "|GIF (*.gif)|*.gif"; _OpenFile_dlg.Filter += "|JPEG (*.jpg, *.jpeg, *.jpe, *.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif"; _OpenFile_dlg.Filter += "|PNG (*.png)|*.png"; _OpenFile_dlg.Filter += "|TIFF (*.tif, *.tiff)|*.tif;*.tiff"; _OpenFile_dlg.Filter += "|WMPhoto (*.wdp, *.wmp, *.hdp)|*.wdp;*.wmp;*.hdp"; _OpenFile_dlg.Filter += "|TGA (*.tga)|*.tga"; _OpenFile_dlg.Filter += "|DirectDraw Surface (DDS) (*.dds)|*.dds"; _OpenFile_dlg.Multiselect = false; _OpenFile_dlg.Title = "Открыть"; if (_OpenFile_dlg.ShowDialog() == true) { try { BitmapImage bmp = FileManagementController.OpenImage(_OpenFile_dlg.FileName); this.imageCanvas.Clear(); borderCanvas.Width = bmp.Width; borderCanvas.Height = bmp.Height; this.imageCanvas.AddFirstLayer(bmp); this.imageCanvas.OpenfileName = _OpenFile_dlg.FileName; OpenfileNameChanged(this, new EventArgs()); imageBorder.Visibility = System.Windows.Visibility.Visible; this.imageCanvas.lastChangeSaved = true; if (LayerControl.IsCreated) { layerDialog.UpdateLayersControl(); } } catch (FileFormatException excp) { MessageBox.Show(excp.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception) { MessageBox.Show("Невозможно открыть изображение", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); this.UpdateLayout(); } } }