[英]What's the code-behind equivalent of {Binding}?
該代碼的等效代碼是什么?
<SomeControl SomeProperty="{Binding}"/>
(如果我想在SomeControl的代碼中而不是在使用者的XAML中執行此操作。)
也就是說,如何構造Binding對象,以便直接綁定到當前對象的DataContext,而不是綁定到某些屬性?
由於{Binding}
只是{Binding Path=.}
的快捷方式,因此它應該與
SomeControl.SetBinding(SomeControl.SomeProperty, new Binding("."));
看看BindingOperations.SetBinding :
BindingOperations.SetBinding(myControl, MyControlClass.Property, new Binding(...));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.