Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding to Attached Properties in Xamarin Forms

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)}"
like image 303
The Pademelon Avatar asked Mar 02 '17 00:03

The Pademelon


People also ask

How do you bind property in xamarin forms?

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.

What is attached property in xamarin forms?

Attached properties enable an object to assign a value for a property that its own class doesn't define.

What is binding in xamarin forms?

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.

How do I bind data to grid in xamarin form?

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.


1 Answers

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.

like image 56
Stephane Delcroix Avatar answered Oct 25 '22 03:10

Stephane Delcroix