using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            DataContext = new ObservableCollection<MyObject>(from i in Enumerable.Range(0, 100)
                                                              select new MyObject() { ID = i, Name = String.Format("Name{0}", i) });
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var firstItem = ((ObservableCollection<MyObject>)DataContext).ElementAtOrDefault(0);
            if (firstItem != null)
            {
                firstItem.Name = "Test";
            }
        }
    }

    public class MyObject : INotifyPropertyChanged
    {
        int _ID;
        public int ID
        {
            get
            {
                return _ID;
            }
            set
            {
                if (_ID != value)
                {
                    _ID = value;

                    OnPropertyChanged("ID");
                }
            }
        }

        string _Name;
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                if (_Name != value)
                {
                    _Name = value;

                    OnPropertyChanged("Name");
                }
            }
        }

        #region INotifyPropertyChanged Members

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }

}
