Does Binding work ONLY with DependencyProperty?

后端 未结 2 1791
别那么骄傲
别那么骄傲 2021-02-08 06:51

MSDN says,

  • Each binding typically has these four components: a binding target object, a target property, a binding source, and a Path to th

相关标签:
2条回答
  • 2021-02-08 07:17

    That's correct. If you look at the source code of WPF toolkit controls you can see how it's done. The DataGrid does it in quite a few places (e.g. specific columns passing the Content binding to the cell). I'll try to remember to add a link to a specific file and line where it's done after work.

    Edit A good example is the Binding property in the DataGridBoundColumn class. You can see it used in

    internal void ApplyBinding(DependencyObject target, DependencyProperty property)
    

    If you're interested in advanced patterns to make WPF and Silverlight controls I highly recommend looking through their respective toolkits. They're well-commented in general and some of the controls are using some cool code.

    0 讨论(0)
  • 2021-02-08 07:29

    The XAML is setting Setter.Value to an object of type Binding. The Style thus created then sets the Text dependency property on the target object to that Binding, so that the binding will update Text whenever the source property changes.

    If Setter.Value were a dependency property, then the setter would end up being an intermediary in property-change notification: the source property changes, the binding notifies the setter, the setter notifies the target. Since it's just a CLR property, the setter's not actually involved in change notification: the source property changes and the binding notifies the target.

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