WPF how to detach event hooks in UserControls
-
01-10-2019 - |
Pergunta
I have a WPF UserControl
that contains a ComboBox
. I need to attach an event listener to the ComboBox.Items
collection.
public MyUserControl()
{
InitializeComponent();
((INotifyCollectionChanged)comboBox.Items).CollectionChanged +=
ComboBoxItemsChanged;
}
But I cant seem to figure out how to detach it. Or is that handled automatically when the entire control is garbage collected?
Solução
Implement IDisposable interface and detach event handler in Dispose method
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow