绑定到 Xamarin 表单中的附加属性

The*_*lon 6 xaml xamarin.forms

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

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

BindingContext="{x:Binding Source={x:Reference ControlName}, Path=(XMLNameSpace:ClassName.AttachedPropertyName)}"
Run Code Online (Sandbox Code Playgroud)

Ste*_*oix 5

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

有效的方法是通过某种 ViewModel(可以定义为 StaticResource),并绑定ControlName.AttachedProperty到该 VM 的属性(使用OneWayToSource模式),然后绑定到该临时 VM 的该属性。