1
Vote

No Dispose Method

description

A behavior, after been detached and having the association removed, does not get disposed.
    protected override void OnDetaching()
    {
        base.OnDetaching();
        AssociatedObject.SelectionChanged -= OnSelectionChanged;
 
        Interaction.GetBehaviors(AssociatedObject).Remove(this);
        this.DataContext = null;
    }
 
On every visit of a Page, a new behavior gets created through the xaml Interaction.Behaviors binding.
As a result multiple PropertyChangeEvents get fired causing exceptions.
 
How can the behavior be disposed?

comments