문제

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?

도움이 되었습니까?

해결책

Since {Binding} is just a shortcut for {Binding Path=.}, it should be just as simple as

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

다른 팁

Take a look at BindingOperations.SetBinding:

BindingOperations.SetBinding(myControl, MyControlClass.Property, new Binding(...));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top