Hi,
I am using MVVM in wpf. here is my sample code as below:
Model:
private string fruit; public string Fruit { get { return fruit; } set { fruit = value; OnPropertyChanged("Fruit"); } }
ViewModel:
.................................... private ObservableCollection<DemoModel> fruits = new ObservableCollection<DemoModel>(); public ObservableCollection<DemoModel> Fruits { get { return fruits; } set { fruits = value; OnPropertyChanged("Fruits"); } } public void LoadFruit() { fruits.Add(new DemoModel(null, null) { Fruit = null }); fruits.Add(new DemoModel(null, null) { Fruit = "Mango" }); fruits.Add(new DemoModel(null, null) { Fruit = "Orange" }); } private void ButtonClick(object obj) { foreach (var item in Fruits) { MessageBox.Show(item.ToString()); ??????? }
}
How to get the data foreach observablecollection when i clicked button event?