using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfApplication17
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
List<Student> ModeStudents;
public ObservableCollection<Student> Students { get; set; }
public MyBindingList<Student> Students1 { get; set; }
public Window1()
{
InitializeComponent();
ModeStudents = new List<Student>();
InitData();
//Students.CollectionChanged += Students_CollectionChanged;
this.DataContext = this;
}
void Students_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
//throw new NotImplementedException();
}
private void InitData()
{
List<Student> stu = new List<Student>()
{
new Student{Id="01",Name="name1"},
new Student{Id="02",Name="name2"},
};
//Students = new ObservableCollection<Student>(stu);
Students1 = new MyBindingList<Student>(stu);
}
public class Student : INotifyPropertyChanged
{
private string _Id;
public string Id
{
get { return _Id; }
set
{
_Id = value;
NotifyPropertyChanged("Id");
}
}
private string _Name;
public string Name
{
get { return _Name; }
set
{
_Name = value;
NotifyPropertyChanged("Name");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
public class MyBindingList<T> : BindingList<T>
{
public List<T> ModeList { get; set; }
public MyBindingList()
: base()
{
ModeList = new List<T>();
}
public MyBindingList(IList<T> list)
: base(list)
{
ModeList = new List<T>();
}
protected override void OnListChanged(ListChangedEventArgs e)
{
base.OnListChanged(e);
if (e.ListChangedType == ListChangedType.ItemChanged)
{
ModeList.Add(this.Items[e.NewIndex]);
}
}
}
}
}
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfApplication17
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
List<Student> ModeStudents;
public ObservableCollection<Student> Students { get; set; }
public MyBindingList<Student> Students1 { get; set; }
public Window1()
{
InitializeComponent();
ModeStudents = new List<Student>();
InitData();
//Students.CollectionChanged += Students_CollectionChanged;
this.DataContext = this;
}
void Students_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
//throw new NotImplementedException();
}
private void InitData()
{
List<Student> stu = new List<Student>()
{
new Student{Id="01",Name="name1"},
new Student{Id="02",Name="name2"},
};
//Students = new ObservableCollection<Student>(stu);
Students1 = new MyBindingList<Student>(stu);
}
public class Student : INotifyPropertyChanged
{
private string _Id;
public string Id
{
get { return _Id; }
set
{
_Id = value;
NotifyPropertyChanged("Id");
}
}
private string _Name;
public string Name
{
get { return _Name; }
set
{
_Name = value;
NotifyPropertyChanged("Name");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
public class MyBindingList<T> : BindingList<T>
{
public List<T> ModeList { get; set; }
public MyBindingList()
: base()
{
ModeList = new List<T>();
}
public MyBindingList(IList<T> list)
: base(list)
{
ModeList = new List<T>();
}
protected override void OnListChanged(ListChangedEventArgs e)
{
base.OnListChanged(e);
if (e.ListChangedType == ListChangedType.ItemChanged)
{
ModeList.Add(this.Items[e.NewIndex]);
}
}
}
}
}