I'm creating LayoutAnchorable dynamically and adding it to a parent. A button fires this code and created layoutAnchrable, listbox and some content in it.
LayoutAnchorable layoutAnchorable = new LayoutAnchorable
{
Content = listBox,
Title = _selectedSchema.Value,
ContentId = _selectedSchema.Key,
IsActive = true,
IsSelected = true,
CanFloat = true,
CanAutoHide = false,
CanClose = true,
CanHide = false,
};
if(!panelXml.Children.Select(x => x.ContentId).Contains(layoutAnchorable.ContentId))
{
panelXml.Children.Add(layoutAnchorable);
}
else
{
panelXml.Children.Remove(layoutAnchorable);
}
If there is the same layoutAnchorable in Children I want to remove it from the children list.
I traced the code and it works just fine but panelXml.Children.Remove(layoutAnchorable);
does not work.