0
votes

I am trying to use MVVM in my WPF application which displays data from a class in the business logic layer called 'Employee' with a property 'Salary'. I have a simple XAML window with a text box with binding to the Salary property in a ViewModel class 'EmployeeViewModel'. The ViewModel implements INotifyPropertyChanged so that when the Salary property of the EmployeeViewModel changes, the value in the XAML text box also changes. All that works fine.

Now, the Salary property of EmployeeViewModel gets its value from the Salary property of the Employee class. However, if the Salary value of the Employee class is changed by some other procedure going on in the business logic layer, it does not automatically update in the EmployeeViewModel. What is the best way to get it to do this? I was thinking some kind of INotifyPropertyChanged implementation in the Employee class which would let the EmployeeViewModel know to update itself. Or should I use a Dependency Property? Or should I have procedure which 'refreshes' the ViewModel once all of the changes in the business logic layer have been completed. Any help appreciated!

2

2 Answers

0
votes

I strongly recommend you to implement INotifyPropertyChanged on your business object(Employee) and register to changes on your view model.

If you really wanna stay as much poco as you can, you can just declare the interface and add a public method that called RaisePropertyChanged(string propertyName) and just call it when your bussiness logic finish.

0
votes

My thoughts

if you implement INotifyPropertyChanged on your Business Entity, you will create a coupling between your Business Entity and your View Model.

Your Model should not be dependent upon specific feature like INotifypropertychanged.

2- If you are using Prism Framework ,then use EventAgreegator which is a pure decouple way to communicate between modules.

3- your 3rd option point sounds good to me when you say "I have procedure which 'refreshes' the ViewModel once all of the changes in the business logic layer have been completed"