Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View Model property deriving from multiple Model properties #111

Open
ghost opened this issue Feb 1, 2023 · 0 comments
Open

View Model property deriving from multiple Model properties #111

ghost opened this issue Feb 1, 2023 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 1, 2023

How should MVVM Toolkit be used to elegantly derive a property in the ViewModel from multiple properties in the Model (responding to changes in the model)? It seems that the NotifyPropertyChangedFor attribute cannot be used for properties outside of the ViewModel class.

Related question:
By using the NotifyPropertyChangedFor attribute or plain-vanilla "propertychanged" event handlers, you are basically defining that a property B influences property A. At the same time, in the getter of property A you are defining how B influences A, by defining an expression A = F(B). This is unnecessarily redundant. The fact that A = F(B) already implies that any change of B should result in a notification to update A. You could easily make the expression A = F(B) and forget to add the response to change of B, and you will not find it out until testing.
SolSoft.DataBinding tried to solve this, at the price of more complex Model classes:
https://www.nuget.org/packages/SolSoft.DataBinding/
In this case you have a single statement for each derived property in the constructor of your viewmodel. The consequence is that the model classes need to know which properties may influence properties in the ViewModel classes, by exposing property wrapper objects as properties as well. This makes the model classes unnecessarily complex.
Are there better ways to do this using MVVM Toolkit? If needed, can we think of any new features for the toolkit to make this work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants