如何投射 List<T>到 ObservableCollection<T>在wpf? [英] How to cast a List<T> to an ObservableCollection<T> in wpf?
本文介绍了如何投射 List<T>到 ObservableCollection<T>在wpf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 wpf,有一个通用列表:List.现在我希望将其转换为通用的可观察集合:ObservableCollection.
I am in wpf, and have a generic list: List. Now I wish to cast it to a generic observable collections: ObservableCollection.
我知道我可以遍历列表并将每个单独的项目添加到 Observable 集合中.但是,在我看来,必须有一种内置的方式来做到这一点.
I understand I can iterate over the list and add each individual item to the Observable collection. However, it seems to me there has to be a built-in way of doing this.
推荐答案
如果您只想从 List
创建一个 ObservableCollection
,那么您需要做的就是
If you JUST want to create an ObservableCollection
from a List
, then all you need to do is
ObservableCollection<MyType> obsCollection = new ObservableCollection<MyType>(myList);
这篇关于如何投射 List<T>到 ObservableCollection<T>在wpf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文