Continuing on my previous question about the cluttered state of my viewmodel How can I avoid command clutter in the ViewModel?Previous question I have a new question. For a school project I am making a image editing desktop application in WPF using the MVVM pattern. Due to all the editing options (crop resize etc) there are quite a few commands,- that invoke code-heavy methods that use the GDI+ properties and methods, as well as events. ATM the viewmodel is counting 770 lines and that kind of makes me want to cry. Where should methods such as these two (oh my, please keep in mind I started programming four months ago) go?
private void ToGrayscale()
{
Bitmap template = CurrentImage.LoadedImage.ToBitmap();
var drawing = new Bitmap(template.Width, template.Height);
var drawingsurface = Graphics.FromImage(drawing);
var attributes = new ImageAttributes();
attributes.SetColorMatrix(ImageFilters.GrayScaleMatrix);
drawingsurface.DrawImage(template, new System.Drawing.Rectangle(0, 0, template.Width, template.Height),
0, 0, template.Width, template.Height, GraphicsUnit.Pixel, attributes);
drawingsurface.Dispose();
AddSnapshot(drawing, "Desaturate");
CurrentImage.LoadedImage = drawing.ToBitmapImage();
UiImageContainer.Source = CurrentImage.LoadedImage;
}
private void OnMouseMove(object sender, MouseEventArgs args)
{
if (UiImageContainer.IsMouseCaptured && args.GetPosition(UiImageContainer).X > 0 &&
args.GetPosition(UiImageContainer).Y < UiImageContainer.Source.Height && args.GetPosition(UiImageContainer).Y > 0 &&
args.GetPosition(UiImageContainer).X < UiImageContainer.Source.Width)
{
if (_rubberBand == null)
{
_rubberBand = new System.Windows.Shapes.Rectangle();
_rubberBand.VerticalAlignment = VerticalAlignment.Top;
_rubberBand.HorizontalAlignment = HorizontalAlignment.Left;
var partiallyTransparentSolidColorBrush = new SolidColorBrush(Colors.White);
partiallyTransparentSolidColorBrush.Opacity = 0.25;
_rubberBand.Fill = partiallyTransparentSolidColorBrush;
_rubberBand.Stroke = new SolidColorBrush(Colors.LightGray);
ContentGrid.Children.Add(_rubberBand);
}
var width = Math.Abs(_mouseLeftDownPoint.X - CurrentImagePoint.X);
var height = Math.Abs(_mouseLeftDownPoint.Y - CurrentImagePoint.Y);
var left = Math.Min(_mouseLeftDownPoint.X, CurrentImagePoint.X);
var top = Math.Min(_mouseLeftDownPoint.Y, CurrentImagePoint.Y);
_rubberBand.Width = width;
_rubberBand.Height = height;
var size = new Thickness(left, top, 0, 0);
_rubberBand.Margin = size;
}
}