WPF INotifyPropertyChanged for linked read-only properties

后端 未结 7 1366
小鲜肉
小鲜肉 2020-12-30 09:22

I am trying to understand how to update the UI if I have a read-only property that is dependent on another property, so that changes to one property update both UI elements

7条回答
  •  轮回少年
    2020-12-30 09:58

    Depending on the expense of the calculation and how frequently you expect it to be used, it may be beneficial to make it a private set property and calculate the value when foo is set, rather than calculating on the fly when the bar get is called. This is basically a caching solution and then you can do the property change notification as part of the bar private setter. I generally prefer this approach, mainly because I use AOP (via Postsharp) to implement the actual INotifyPropertyChanged boilerplate.

    -Dan

提交回复
热议问题