WPF MVVM - Can a single PropertyChanged update all the Data bindings of a DataTemplate?

前端 未结 2 1304
醉梦人生
醉梦人生 2020-12-24 14:28

I have a ViewModel class which has large number of properties(Say 50). Once the data is set on to all the properties I need to update the UI. I know that the common solution

相关标签:
2条回答
  • 2020-12-24 14:28

    I don't think this a problem worth trying to solve. That is, I think the solution here is to have the individual properties send property-changed notifications as they are set. If not, what are you going to do when an individual property (but not necessarily all fifty) changes?

    0 讨论(0)
  • 2020-12-24 14:32

    Finally I have got an answer from my colleague Josh Smith , it is very simple, we just need to raise a PropertyChanged event with null or String.Empty as property name. which will tell the WPF binding system to re-evaluate all the bindings of that object. I am getting two major advantage while using this.

    1. The overhead of raising individual events on each property will reduce to just one Event from View-Model to the UI. Performance will get increased.
    2. While writing code we can just use {get;set;} syntax which is clean and less writing

    Assumption : As in the question I assumed here that it is a very special condition in which all my Properties are getting updated at the same time

    I have a blogpost discussing this here

    Update: based on the comment from kek444

    0 讨论(0)
提交回复
热议问题