To Observable Collection - CSharp System.Collections.ObjectModel

CSharp examples for System.Collections.ObjectModel:ObservableCollection

Description

To Observable Collection

Demo Code


using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Media;
using System.Windows.Input;
using System.Windows.Ink;
using System.Windows.Documents;
using System.Windows.Controls;
using System.Windows;
using System.Net;
using System;/*from   w w  w .j a v a2  s. c om*/

public class Main{
        internal static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> enumerableList)
        {
            if (enumerableList != null)
            {
                //create an emtpy observable collection object
                var observableCollection = new ObservableCollection<T>();

                //loop through all the records and add to observable collection object
                foreach (var item in enumerableList)
                {
                    observableCollection.Add(item);
                }

                //return the populated observable collection
                return observableCollection;
            }

            return null;
        }
}

Related Tutorials