什么是 {绑定} 的代码隐藏等效项

本文关键字:隐藏 代码 绑定 什么 | 更新日期: 2023-09-27 18:35:14

此代码的代码隐藏等效项是什么?

<SomeControl SomeProperty="{Binding}"/>

(如果我想在 SomeControl 的代码隐藏中而不是在使用者的 XAML 中执行此操作。

也就是说,如何构造一个绑定对象,以便我直接绑定到当前对象的 DataContext,而不是绑定到某个属性?

什么是 {绑定} 的代码隐藏等效项

由于{Binding}只是{Binding Path=.}的快捷方式,它应该像

SomeControl.SetBinding(SomeControl.SomeProperty, new Binding("."));

看看 BindingOperations.SetBinding:

BindingOperations.SetBinding(myControl, MyControlClass.Property, new Binding(...));