public void AddChild(UIElement child) { if (child.Parent != null) { throw new Exception("Tried to add a child that already has a parent!"); } if (!Children.Contains(child)) { if (!ToAdd.Add(child)) { throw new Exception("Tried to add a child twice!"); } } else { throw new Exception("Tried to add a child that already belongs to this element!"); } }
public void RemoveChild(UIElement child) { if (Children.Contains(child)) { if (!ToRemove.Add(child)) { throw new Exception("Tried to remove a child twice!"); } } else { throw new Exception("Tried to remove a child that does not belong to this element!"); } }
public bool HasChild(UIElement element) { return Children.Contains(element) && !ToRemove.Contains(element); }