views:

22

answers:

1

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.

A: 

As workaround I have implemented an interface IActiveAware with IsActive property, which is false when the logical life of user control has ended. On the bound property in ViewModel I check this property.

Dmitry