有没有一种方法,以可观察集合转换为定期收集? [英] Is there a way to convert an observable collection to regular collection?

查看:128
本文介绍了有没有一种方法,以可观察集合转换为定期收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试集的设置为:

I've got a test collection setup as :

ObservableCollection<Person> MyselectedPeople = new ObservableCollection<Person>();

public MainWindow()
    {
       InitializeComponent();
       FillData();
    }

public void FillData()
    {
        Person p1 = new Person();
        p1.NameFirst = "John";
        p1.NameLast = "Doe";
        p1.Address = "123 Main Street";
        p1.City = "Wilmington";
        p1.DOBTimeStamp = DateTime.Parse("04/12/1968").Date;
        p1.EyeColor = "Blue";
        p1.Height = "601";
        p1.HairColor = "BRN";

        MyselectedPeople.Add(p1);
    }



一旦我有这个集合构成,我想能够在观测转换集合类型列表中。

Once I have this collection built I would like to be able to convert the Observable Collection to the type List.

这背后的原因是我的主要项目正在接收数据我必须将它转化成可观察集合用于GridView的泛型列表,列表框等数据在用户界面中选择,然后送回作进一步使用原始装配。

The reason behind this is my main project is receiving a generic list with data I have to convert it to an Observable collection for use in gridview, listboxes etc. Data is selected within the UI and then sent back to the originating assembly for further usage.

推荐答案

我想最快。这样做,这是使用LINQ

I think the quickest way to do this is with LINQ.

 List<Person> personList= MySelectedPeople.ToList(); 



干杯。

Cheers.

这篇关于有没有一种方法,以可观察集合转换为定期收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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