When should I use dependency properties in WPF?

前端 未结 6 443
北荒
北荒 2020-12-08 14:51

When should I use dependency properties in WPF?

They are static, so we save a lot on memory, compared to using .NET properties. Other gains of using dependency prope

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 15:14

    Dependency properties are used when you want data binding in a UserControl, and is the standard method of data binding for the WPF Framework controls. DPs have slightly better binding performance, and everything is provided to you when inside a UserControl to implement them.

    Otherwise, you typically use INotifyPropertyChanged for binding elsewhere, since it's easier to implement in stand-alone classes and has less overhead. As far as your original assumptions:

    1. There is a local instance of your variable, you definitely do not save any overhead over a property since there is significant data binding logic built-in.
    2. They must be accessed on the main thread.

提交回复
热议问题