如何在 C# 中创建 Observable Hashset? [英] How can I make an Observable Hashset in C#?

查看:13
本文介绍了如何在 C# 中创建 Observable Hashset?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我在 WPF 应用程序中使用 ObservableCollection,该应用程序是 Conway's Game of life 的一个实现,在大约 500 个单元格中运行良好,但之后它开始显着减慢.我最初使用 HashSet 编写应用程序,但找不到任何方法将单元格绑定到画布.

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.

有没有办法让我的 HashSet 将更改通知其绑定对象?我的 Cell 类是一个简单的整数 X,Y 对,如果该对存在,则单元格是活的,否则是死的.Cell 实现 INotifyPropertyChanged 并覆盖 GetHashCode 和 Equals.我无法让单元格显示任何更改,只有加载后立即出现的单元格.有没有办法将 Hashset 绑定到 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?

推荐答案

您必须实施 INotifyCollectionChanged 也是如此,然后它应该一切正常.还有另一个相关的 SO 答案 使用 freezables以确保基础实体的变化也得到处理.

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# 中创建 Observable Hashset?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆