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)}"
The binding references the source object. To set the data binding, use the following two members of the target class: The BindingContext property specifies the source object. The SetBinding method specifies the target property and source property.
Attached properties enable an object to assign a value for a property that its own class doesn't define.
Data binding is the technique of linking properties of two objects so that changes in one property are automatically reflected in the other property. Data binding is an integral part of the Model-View-ViewModel (MVVM) application architecture.
Binding ItemsSource in XAML In the main page, add the necessary XML namespace to use SfDataGrid control, set the BindingContext of the page to the ViewModel class, and bind the ItemSource of SfDataGrid with the DataTableCollection.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With