maui
maui copied to clipboard
Make Typed `SetBinding()` method generic so that the `BindableProperty` need not be prefixed with the type name
Description
Make the Typed SetBinding() method generic so that the BindableProperty need not be prefixed with the type name.
By doing so, all the bindable properties of the object that invokes this method will be accessible.
Public API Changes
public static void SetBinding<TBindableObject, TSource, TProperty>(this TBindableObject bindable, BindableProperty targetProperty, Func<TSource, TProperty> getter /* all other parameters */) where TBindableObject : BindableObject {}
Intended Use-Case
var lbl = new Label();
// Current scenario:
lbl.SetBinding(Label.TextProperty, static (HomeViewModel vm) => vm.FullName);
// Updated scenario
// TextProperty is now accessible in the scope
lbl.SetBinding(TextProperty, static (HomeViewModel vm) => vm.FullName);
When using generics, the method call becomes associated with the invocation object instance rather than the base BindableObject type.
Is there a way for this method to return the updated instance of the BindableObject itself rather than returning void?
Is there any impediment to this? Enabling this would facilitate method call chaining.
What is so special about bindable properties of the VisualElement type as I can refer to those properties without the type name prefix?