Updating properties and enabling commands that depend on observable object fields #905
Unanswered
djordje200179
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
As we know,
RelayCommandand getter-only properties need to be notified when their dependencies change. That is usually done withNotifyCanExecuteChangedForAttributeandNotifyPropertyChangedForAttribute.But what needs to be done in cases when we access nested object fields, and not primitive types? I know that those classes also need to implement
INotifyPropertyChanged. But that is not enough here, because that event isn't propagated to cause reevaluation ofCanExecutemethod.Here is an example:
There is an object of
Bill.Itemclass that implementsINotifyPropertyChanged(I have tried to use bothObservableObjectand Fody.PropertyChange, but there is no difference).SaveCommandandNotEnoughDrinksproperty depend on fields insideBillItem.I have found a workaround, by subscribing to
PropertyChangedevent and manually invokingOnPropertyChangedandNotifyCanExecuteChanged. Unfortunately that solution producesCOMExceptionandTargetInvocationExceptionfrom time to time, and I am unable to find the root cause, or any message related to those exceptions. And except from that issue, I assume that this solution is not idiomatic enough because it makes code more complex.Is there anything that I am missing, for example an attribute, that is useful for these cases when I need to handle updates of nested
ObservableObjectfields? Or I really need to stick to workarounds like the one shown above?Beta Was this translation helpful? Give feedback.
All reactions