2

What's the code-behind equivalent of this code?

<SomeControl SomeProperty="{Binding}"/>

(If I wanted to do that in the code-behind of SomeControl instead of in the consumer's XAML.)

That is, how do I construct a Binding object such that I bind directly to the DataContext of my current object, instead of to some property?

4

2 回答 2

5

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

SomeControl.SetBinding(SomeControl.SomeProperty, new Binding("."));
于 2012-05-24T06:58:52.440 回答
0

看看BindingOperations.SetBinding

BindingOperations.SetBinding(myControl, MyControlClass.Property, new Binding(...));
于 2012-05-24T07:02:09.237 回答