public ImageEditor(string filename, Size size) { _model = new CropModel { TargetWidth = size.Width, TargetHeight = size.Height }; DataContext = this; InitializeComponent(); Buttons = new[] { CreateExtraDialogButton(AppStrings.CropImage_Skip, () => { Result = _image; Close(); }), OkButton, CancelButton }; _image = new BitmapImage(); _image.BeginInit(); _image.UriSource = new Uri(filename); _image.EndInit(); OriginalImage.SetCurrentValue(Image.SourceProperty, _image); if (_image.IsDownloading) { _image.DownloadCompleted += Image_Loaded; } else { Image_Loaded(this, null); } Closing += (sender, args) => { if (MessageBoxResult != MessageBoxResult.OK) return; var rect = new Int32Rect((int) _model.OffsetX, (int) _model.OffsetY, (int) _model.ImageWidth, (int) _model.ImageHeight); var cropped = new CroppedBitmap(_image, rect); Result = cropped.Resize((int) _model.TargetWidth, (int) _model.TargetHeight); }; }