绑定到 Xamarin 表单中的附加属性 [英] Binding to Attached Properties in Xamarin Forms

查看:31
本文介绍了绑定到 Xamarin 表单中的附加属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何绑定到 Xamarin Forms XAML 中的附加属性?

How can I bind to an attached property in Xamarin Forms XAML?

这不起作用,但它可以编译并且最有意义:

This doesn't work but it compiles and makes the most sense:

BindingContext="{x:Binding Source={x:Reference ControlName}, Path=(XMLNameSpace:ClassName.AttachedPropertyName)}"

推荐答案

您不能使用附加的 BindableProperty 作为绑定源,因为在您引用的 Control 中没有支持该 BP 的属性来源.我想不出任何方法可以直接使用绑定来完成这项工作.

You can not use an attached BindableProperty as binding source, as there is no property backing up that BP in the Control you reference as Source. I can't think of any way making this work directly with bindings.

通过某种 ViewModel(可以定义为静态资源),并将 ControlName.AttachedProperty 绑定到该 VM 的属性(使用 OneWayToSource 模式),然后绑定到该临时 VM 的该属性.

What will work is going through a ViewModel of some sort (can be defined as a StaticResource), and bind ControlName.AttachedProperty to a property of that VM (using OneWayToSource mode) and then bind to that property of that temporary VM.

这篇关于绑定到 Xamarin 表单中的附加属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆