简体   繁体   English

WPF ComboBox SelectionChangedEventHandler删除了吗?

[英]WPF ComboBox SelectionChangedEventHandler remove?

I have a WPF ComboBox: 我有一个WPF ComboBox:

 <ComboBox x:Name="MyDropDown" TabIndex="1" SelectedIndex="1">
     <ComboBox.Items>
         <ComboBoxItem>ComboBox Item #1</ComboBoxItem>
         <ComboBoxItem>ComboBox Item #2</ComboBoxItem>
     </ComboBox.Items>                                            
</ComboBox>

And in my CodeBehind I have a handler: 在我的CodeBehind中,我有一个处理程序:

MyDropDown.SelectionChanged += new SelectionChangedEventHandler(MyDropDown_SelectionChanged);

Do I have to remove this MyDropDown_SelectionChanged from MyDropDown in the Dispose of my class? 我必须在“处置我的课程”中从MyDropDown删除此MyDropDown_SelectionChanged吗?

Unless you expect the publisher of the event to outlive the subscriber, there's no reason to remove the event handler, no. 除非您期望事件的发布者超过订阅者的生命,否则没有理由删除事件处理程序。 Dispose serves mainly for releasing resources like DB connections or files. Dispose主要用于释放数据库连接或文件之类的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM