-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
OnPropertyChanged is called twice if we use the ViewModelToModel attribute #531
Comments
Could it be because it's actually called "Property"? There is an "OnPropertyChanged" virtual method and the property is called OnPropertyChanged. Or does it happen to any sort of property name? |
the name of the property does not matter. |
I've written reproducable unit tests. Will investigate why this happens. |
Generated code:
|
It also seems to happen to Catel 5 (according to the unit tests). It's probably because the ObservableObject does not do a equality check before raising the property. There could be 2 solutions here (but I think both need to be fixed in Catel itself):
|
Yes, ObservableObject does not check the old value before setting it again. |
It only happens to ObservableObject (not ModelBase) because the ModelBase does equality checks under the hood. I think the best way to solve this is in the ViewModelBase since we can never rely on any model handling this correctly. |
Closing this ticket in favor of the Catel one (this will be (is actually) fixed in Catel itself). |
btw the other request is covered by #357 , but that will only solve this issue when using the Catel one. If you use any others, it would still fail (hence the fix in Catel itself). |
Ok, I'm waiting for a fix in Catel. |
Please check all of the platforms you are having the issue on (if platform is not listed, it is not supported)
Component
ViewModel
Version of Library
Catel.Core 6.0.1
Catel.Fody 4.9.0
Version of OS(s) listed above with issue
Windows 11
Steps to Reproduce
Here is test code:
We have TestModel object and a ViewModel that uses it. ViewModel exposes the property from the TestModel object by using the attribute [ViewModelToModel].
Expected Behavior
after changing the property function OnPropertyChanged() should be called, one time.
Actual Behavior
OnPropertyChanged() is called twice. And output from creating MyDerivedViewModel is:
Property changed: test 1
Property changed: test 2
If instead of " Model.Property = "test";" we will use the code Property = "test"; OnPropertyChanged is called once
The text was updated successfully, but these errors were encountered: