简体   繁体   English

WPF C#DataBinding列表终结

[英]WPF C# DataBinding List Finalization

I have implemented a user control that contains a ListBox that is bound to a List: 我已经实现了一个用户控件,其中包含一个绑定到List的ListBox:

listBox1.ItemsSource = list;

I have implemented a method that removes the (only) reference to the list: 我已经实现了一个删除(仅)引用列表的方法:

listBox1.ItemsSource = null;

Having called this method, I force garbage collection: 调用此方法后,我强制垃圾收集:

GC.Collect();

The destructor of my list class is not being called. 我的列表类的析构函数没有被调用。 There is obviously some hidden reference to the list. 显然有一些隐藏的参考列表。

Any explanation of this behavior would be gratefully received. 将非常感激地收到对此行为的任何解释。

list不为null,所以它仍然存在。

list = null;

解决方案是从ObservableCollection(或实现INotifyCollectionChanged的东西)而不是List派生列表类。

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

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