6
votes

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)}"
1

1 Answers

4
votes

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.

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.