TheJoeIaut
TheJoeIaut

Reputation: 1532

Receive RaisePropertyChanged in Viewmodel (MVVM Light)

I got this Data Structure:

12 Measurements, each Measurement contains 1-x Cells, each Cell contains 1-x Stations. The Amount of Cells/Stations is the same for each Measurement.

Therefore i have a Measurement, a Cell and a Station Class. Each of these 3 implement the ObservableObject Class.

In my View i create a Itemscontrol for each Measurement to display all Cells of a Measurement. Each Item contains an Itemscontrol to display all the Stations in Textboxes.

Now i need a 13th Measurement in which i calculate the sums from each station across all Measurements. (Station 1 from Cell 1 from all 12 Measurement).

Currently my Viewmodel only contains a Observable Collection with the 12 Basic Measurements.

How can i detect if a Value of a Station-Textbox is changed and what Station has been changed?

Upvotes: 3

Views: 2284

Answers (2)

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31641

You could latch onto the PropertyChanged event for each Station in the ViewModel. This is an event handler in ObservableObject that is triggered whenever a property is modified (part of the INotifyPropertyChanged interface).

Upvotes: 1

Louis Kottmann
Louis Kottmann

Reputation: 16628

If you want the UI to refresh not only when an item is added/removed from the collection, but also when an item raise PropertyChanged, use a BindingList instead of an ObservableCollection.
It will raise the ListChanged event, which you can listen to for additional information.

Don't listen directly to PropertyChanged unless you want some .Net event hell.

HTH,

Bab.

Upvotes: 2

Related Questions