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
-
As we know,
RelayCommand
and getter-only properties need to be notified when their dependencies change. That is usually done withNotifyCanExecuteChangedForAttribute
andNotifyPropertyChangedForAttribute
.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 ofCanExecute
method.Here is an example:
There is an object of
Bill.Item
class that implementsINotifyPropertyChanged
(I have tried to use bothObservableObject
and Fody.PropertyChange, but there is no difference).SaveCommand
andNotEnoughDrinks
property depend on fields insideBillItem
.I have found a workaround, by subscribing to
PropertyChanged
event and manually invokingOnPropertyChanged
andNotifyCanExecuteChanged
. Unfortunately that solution producesCOMException
andTargetInvocationException
from 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
ObservableObject
fields? Or I really need to stick to workarounds like the one shown above?Beta Was this translation helpful? Give feedback.
All reactions