private void Unselect_Executed(object sender, ExecutedRoutedEventArgs e) { if (e.Parameter is ISelectable) { SelectionService.RemoveFromSelection(e.Parameter as ISelectable); } }
//Adding and Removing DesignerItem On Collection Changed private void OnElementsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { foreach (ElementVM newItem in e.NewItems) { DesignerItem NewDesignerItem = new DesignerItem(); NewDesignerItem.DataContext = newItem; this.Children.Add(NewDesignerItem); NewDesignerItem.ActivateConnectors(); NewDesignerItem.Focus(); SelectionService.SelectItem(NewDesignerItem); Canvas.SetZIndex(NewDesignerItem, this.Children.Count); } } if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (ElementVM removedItem in e.OldItems) { DesignerItem ToRemove = GetDesignerItemByGuid(removedItem.ID); Control cd = ToRemove.Template.FindName("PART_ConnectorDecorator", ToRemove) as Control; List <Connector> connectors = new List <Connector>(); GetConnectors(cd, connectors); foreach (Connector connector in connectors) { foreach (Connection con in connector.Connections) { SelectionService.RemoveFromSelection(con); this.Children.Remove(con); } } SelectionService.RemoveFromSelection(ToRemove); this.Focus(); this.Children.Remove(ToRemove); } } }