The OnPropertyChanged() method would need to use reflection to get the value. also the passed name is just specified in an attribute, it does not specify an actual underlying property (or object if nested).
I am using the MVVM pattern and I want to get the value of the property in the OnPropertyChanged event
I want to get the value of the property in the OnPropertyChanged event. I would rather not use reflection.
Developer technologies | .NET | .NET MAUI
Developer technologies | C#
2 answers
Sort by: Most helpful
-
Bruce (SqlWork.com) 81,616 Reputation points Volunteer Moderator
2024-07-10T21:21:10.8366667+00:00 -
Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,151 Reputation points Microsoft External Staff
2024-07-12T02:52:33.5933333+00:00 Hello,
It is unfeasible to get the value in the
PropertyChangedevent. The reason is as follows.In the
OnPropertyChangedevent, it serves to notify other components that the value of this property has changed. Therefore, in this event you will only find the property PropertyName and not the value. when using this method, it is common to manually assign the value in the setter method and then call this method. You could refer to the following documentation.Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.