private void ModelShapeChanged(object sender, ShapeChangedEventArgs e) { Model.Shape shape = e.Shape; if (e.Removed) { if (_shapes.ContainsKey(shape)) { _sprites.Remove(_shapes[shape]); _shapes.Remove(shape); if (shape is Model.Adorner) { adorner = new KeyValuePair <Model.Adorner, FrameworkElement>(); } } else { throw new ElementNotFoundException(); } } else { if (!_shapes.ContainsKey(shape)) { FrameworkElement shapeControl = null; switch (e.Type) { case ShapeType.Rectangle: shapeControl = DrawHelper.RectangleControlFactory(shape as Model.Rectangle); break; case ShapeType.Line: shapeControl = DrawHelper.LineControlFactory(shape as Model.Line); break; case ShapeType.Ellipse: shapeControl = DrawHelper.EllipseControlFactory(shape as Model.Ellipse); break; case ShapeType.Adorner: shapeControl = DrawHelper.AdornerControlFactory(shape as Model.Adorner); adorner = new KeyValuePair <Model.Adorner, FrameworkElement>((Model.Adorner)shape, shapeControl); break; } _shapes[shape] = shapeControl; _sprites.Add(shapeControl); } else { FrameworkElement shapeControl = _shapes[shape]; if (shape is Model.Line) { DrawHelper.SetCanvasLocation(shapeControl, 0, 0, 100); ((System.Windows.Shapes.Line)shapeControl).X1 = shape.Start.X; ((System.Windows.Shapes.Line)shapeControl).X2 = ((Model.Line)shape).End2.X; ((System.Windows.Shapes.Line)shapeControl).Y1 = shape.Start.Y; ((System.Windows.Shapes.Line)shapeControl).Y2 = ((Model.Line)shape).End2.Y; } else { DrawHelper.SetCanvasLocation(shapeControl, shape.Start.X, shape.Start.Y, 100); shapeControl.Width = shape.Area.Width; shapeControl.Height = shape.Area.Height; } RotateShape(shape, shapeControl); } } }