简体   繁体   English

如何用WPF ListView绑定ConcurrentDictionary?

[英]How to bind ConcurrentDictionary with WPF ListView?

I don't have much experience with ListView nor with binding. 我对ListView和绑定没有太多经验。

I have ConcurrentDictionary 我有ConcurrentDictionary

Where the key is long, and Test is a class that has several public attributes. 密钥很长,而Test是具有几个公共属性的类。

I want to have a list view with columns showing some of those attributes (no editing is required), and when a user selects an item from the list, can access the corresponding Test object. 我想要一个带有显示这些属性中的某些列的列表的列表视图(无需编辑),并且当用户从列表中选择一个项目时,可以访问相应的Test对象。

I want to make sure also that the operations would be thread-safe as I am using a Concurrent Dictionary where tasks can add items to it at anytime. 我还想确保操作是线程安全的,因为我正在使用并发字典,任务可以随时向其中添加项目。

I am using .Net Framework 4.5, Visual Studio 2012. 我正在使用.Net Framework 4.5,Visual Studio 2012。

Write value converter for this. 为此编写值转换器。 On items adding you can just notify whole dict view model (which implements INotifyPropertyChanged ) property changed and list will be repopulated. 在添加项目时,您只需通知整个dict视图模型(实现INotifyPropertyChanged )属性已更改,并且列表将重新填充。 But you can wrap ConcurrentDictionary in your collection which implements INotifyCollectionChanged . 但是您可以将ConcurrentDictionary包装在实现INotifyCollectionChanged的集合中。 Examples: here and here 示例: 这里这里

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

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