开发者

WPF how to detach event hooks in UserControls

开发者 https://www.devze.com 2023-01-13 15:09 出处:网络
I have a WPF UserControl that contains a ComboBox. I need to attach an event listener to the ComboBox.Items collection.

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)combo开发者_StackOverflow中文版Box.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?


Implement IDisposable interface and detach event handler in Dispose method

0

精彩评论

暂无评论...
验证码 换一张
取 消