I don't believe there are any public APIs available in Xamarin.Forms
to access to the BindingExpression
- but you can use reflection to access the associated Binding
and thus the BindingExpression
public static class BindingObjectExtensions
{
public static Binding GetBinding(this BindableObject self, BindableProperty property)
{
var methodInfo = typeof(BindableObject).GetTypeInfo().GetDeclaredMethod("GetContext");
var context = methodInfo?.Invoke(self, new[] { property });
var propertyInfo = context?.GetType().GetTypeInfo().GetDeclaredField("Binding");
return propertyInfo?.GetValue(context) as Binding;
}
public static object GetBindingExpression(this Binding self)
{
var fieldInfo = self?.GetType().GetTypeInfo().GetDeclaredField("_expression");
return fieldInfo?.GetValue(self);
}
}
Sample usage - Get binding-expression
var expr = this.GetBinding(TextProperty).GetBindingExpression();
Sample usage - Get binding path (update 07/27)
//to access path - you can directly use the binding object
var binding = this.GetBinding(TextProperty);
var path = binding?.Path;