如何在C#中创建可观察的Hashset? [英] How can I make an Observable Hashset in C#?
问题描述
有没有办法让我的HashSet通知它的绑定改变对象?我的单元类是一个简单的整数X,Y对,如果对存在,单元格是活的,否则死。 Cell实现INotifyPropertyChanged并覆盖GetHashCode和Equals。我无法让单元格显示任何更改,只是在加载后立即出现单元格。有没有办法将Hashset绑定到画布上的项目?
您必须实现 INotifyCollectionChanged ,然后它应该都可以正常工作。还有一个相关的SO答案,使用freezables 以确保基础实体的更改也处理。
Currently I am using an ObservableCollection within a WPF application, the application is an implementation of Conway's Game of life and works well for about 500 cells but after that it begins to slow down significantly. I originally wrote the application using a HashSet but couldn't find any way to bind the cells to a canvas.
Is there a way to get my HashSet to notify its binding object of changes? My Cell class is a simple integer X,Y pair, if the pair exists the cell is alive otherwise dead. The Cell implements INotifyPropertyChanged and overrides GetHashCode and Equals. I couldn't get the cell to display any changes, just the cells present immediately after loading. Is there any way to Bind a Hashset to items on a Canvas?
You have to implement INotifyCollectionChanged too, and then it should all work OK. There's another relevant SO answer which uses freezables to ensure that changes in underlying entities are also handled.
这篇关于如何在C#中创建可观察的Hashset?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!