Convert List to ObservableCollection in WP7

后端 未结 10 945
不知归路
不知归路 2020-12-25 10:10

I don\'t know if it\'s just too late or what, but I don\'t see how to do this...

What I\'m expecting to do, and what the object browser says is there, is this:

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-25 10:28

    I made an extension so now I can just load a collection with a list by doing:

    MyObservableCollection.Load(MyList);
    

    The extension is:

    public static class ObservableCollectionExtension
    {
      public static ObservableCollection Load(this ObservableCollection Collection, List Source)
      {
              Collection.Clear();    
              Source.ForEach(x => Collection.Add(x));    
              return Collection;
       }
    }
    

提交回复
热议问题