using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;
using System.ComponentModel;

namespace BindingToSelectedRecord_Wpf_2009_Q12
{
	public class Context : INotifyPropertyChanged
	{
		private int selectedIndex;
		private object selectedItem;

		public object ItemsSource
		{
			get;
			set;
		}


		public object SelectedItem
		{
			get
			{
				return selectedItem;
			}
			set
			{
				selectedItem = value;
				this.OnPropertyChanged(new PropertyChangedEventArgs("SelectedItem"));
			}
		}

		public int SelectedIndex
		{
			get
			{
				return this.selectedIndex;
			}
			set
			{
				this.selectedIndex = value;
				this.ChangeSelectedItem();
			}
		}

		private void ChangeSelectedItem()
		{
			IList list = (IList)this.ItemsSource;

			this.SelectedItem = list[this.selectedIndex];
		}

		private void OnPropertyChanged(PropertyChangedEventArgs args)
		{
			if (this.PropertyChanged != null)
				this.PropertyChanged(this, args);
		}

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		#endregion
	}
}
