You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MAUI currently has two general purpose binding classes: Binding and TypedBinding<TSource, TProperty>. The TypedBinding class isn't public and it can only be used through XAML code compiled using XamlC or through the .NET MAUI Markup Community Toolkit.
I'm proposing a new API which will allow developers to define type-safe bindings directly. There are several nice properties of the new API:
IDE IntelliSense shows suggestions when defining the binding
the performance seems to be on par with manually defined TypedBinding (*)
we can assemble the array of handlers for the TypedBinding constructor and customers don't need to define it manually which would be the case if we just made the class public
(*): Based on running the SpeedTestApply and SpeedTestSetBC unit tests in a PoC implementation (net9.0...simonrozsival:maui:typed-binding-from-expression). The PoC also shows that adding System.Linq.Expressions to the dotnet new maui app adds 89,862 B to the final .ipa (1.25 %)
bindableObject.SetBinding(SomeProperty,static(SomeTypesource)=>source.Simple.Path);// for paths with custom indexers, it is not possible to generate the setter from the expression,// so an explicit setter is required:bindableObject.SetBinding(SomeProperty,getter:static(SomeTypex)=>x.Path.To.Property[1],setter:static(x,value)=>x.Path.To.Property[1]=value);
Notes
Typed bindings still don't support relative binding sources. I suspect this is one of the reasons why the TypedBinding type hasn't been made available to public yet and why it's only used by XamlC where it is applicable.
Description
MAUI currently has two general purpose binding classes:
BindingandTypedBinding<TSource, TProperty>. TheTypedBindingclass isn't public and it can only be used through XAML code compiled using XamlC or through the .NET MAUI Markup Community Toolkit.I'm proposing a new API which will allow developers to define type-safe bindings directly. There are several nice properties of the new API:
dotnet new maui#19397)TypedBinding(*)TypedBindingconstructor and customers don't need to define it manually which would be the case if we just made the class public(*): Based on running the
SpeedTestApplyandSpeedTestSetBCunit tests in a PoC implementation (net9.0...simonrozsival:maui:typed-binding-from-expression). The PoC also shows that adding System.Linq.Expressions to thedotnet new mauiapp adds89,862 Bto the final .ipa (1.25 %)Public API Changes
Intended Use-Case
Currently:
Using the new API:
Notes
Typed bindings still don't support relative binding sources. I suspect this is one of the reasons why the
TypedBindingtype hasn't been made available to public yet and why it's only used by XamlC where it is applicable./cc @StephaneDelcroix