I have a set of UserControl, which share the same business object (ViewModel), but only display data from this in different way.
I select an active UserControl via combobox. Old UserControl I delete from StackPanel and add new UserControl.
var uiElement = thisObject.EditorsContainer.Children.FirstOrDefault();
if (uiElement != null)
{
thisObject.EditorsContainer.Children.Remove(uiElement);
uiElement.Cast<UserControl>().ClearValue(DataContextProperty);
}
EditorsContainer is the StackPanel
It looks like a parent control keeps reference on the deleted control, because when I edit value in active control, the binding to binded property updates deleted control in memory.