private void Shapes_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: (e.NewItems[0] as INotifyPropertyChanged).PropertyChanged += Shapes_PropertyChanged; ShapesListMenu.IsEnabled = true; switch (e.NewItems[0]) { case MyPoint point: CanvasPaint.Children.Add(NewShapeForCancas(point)); ShapesListMenu.IsEnabled = false; break; case MyPolygon polygon: CanvasPaint.Children.Add(NewShapeForCancas(polygon)); break; default: break; } if (!(e.NewItems[0] is MyPoint) && !isOpen) { bus.ChooseShape((e.NewItems[0] as MyShape).Name); bus.FillShape(GetColor()); bus.ClearChoose(); } break; case NotifyCollectionChangedAction.Remove: switch (e.OldItems[0]) { case MyPoint point: var points = CanvasPaint.Children.OfType <Ellipse>().Where(p => p.Name == MyPoint.pointName).ToList(); foreach (var item in points) { CanvasPaint.Children.Remove(item); } break; default: break; } break; case NotifyCollectionChangedAction.Reset: ShapesListMenu.IsEnabled = false; action = null; CanvasPaint.Children.Clear(); break; } }
private void ShapeItem_Click(object sender, RoutedEventArgs e) { bus.isNewPolyline = false; Fill.IsEnabled = false; switch (((MenuItem)sender).Name) { case "Ellipse": action = bus.CreateEllipse; bus.ClearChoose(); break; case "Pentagon": action = bus.CreatePentagon; bus.ClearChoose(); break; case "Hexagon": action = bus.CreateHexagon; bus.ClearChoose(); break; case "Polygon": action = bus.CreatePolygon; bus.ClearChoose(); break; case "Polyline": action = bus.CreatePolyline; bus.ClearChoose(); break; case "Fill": bus.FillShape(GetColor()); Fill.IsEnabled = true; break; default: action = null; bus.ClearChoose(); break; } CanvasPaint.MouseMove -= CanvasContainer_MouseMove; }