Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

ObservableCollection Foreach

$
0
0

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?



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>