public partial class MainWindow : Window
{
class1 a = new class1();
ObservableCollection<class1> bindingData = new ObservableCollection<class1>();
public MainWindow()
{
InitializeComponent();
InitDataBinding();
}
void InitDataBinding()
{
a.AA = "aaaaa";
a.BB = true;
bindingData.Add(a);
ShowBBValue.DataContext = this.a;
dataGrid.ItemsSource = bindingData;
}
}
public class class1 : INotifyPropertyChanged
{
private bool _bb;
private string _aa;
public string AA
{
get { return _aa; }
set { this._aa= value; OnPropertyChanged("AA"); }
}
public bool BB
{
get { return this._bb; }
set
{
this._bb= value;
OnPropertyChanged("BB");
}
}
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}