[英]Set equivalent of {Binding .} from code behind in Xamain?
我目前正在从后面的代码中设置一个 label 绑定,它工作正常,如下所示:
lblLabel.SetBinding(Label.TextProperty, model.DataField);
但是,我现在需要向 Label 添加多个绑定(model.Title 和 model.DataField),因此想要绑定整个 BindingContext 以在转换器中使用,在 XAML 中我将使用:
{Binding .}
所以从后面的代码中尝试了以下内容,但这只是将 null 传递给转换器?
lblLabel.SetBinding(Label.TextProperty, ".", BindingMode.Default, new ModelToStringConverter());
这有可能从后面的代码实现还是只能使用“。” 直接在 XAML 中?
相当于 XAML 的"."
this
是。
对于您的场景,您需要将路径作为字符串,因此您可以使用"."
通过创建一个新的Binding
:
ModelToStringConverter modelToStringConverter = new ModelToStringConverter();
txtBlock.SetBinding(TextBlock.TextProperty, new Binding(".", converter: modelToStringConverter);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.