dotnet / docs-maui

This repository contains documentation for .NET Multi-platform App UI (MAUI).
https://docs.microsoft.com/dotnet/maui
Creative Commons Attribution 4.0 International
216 stars 187 forks source link

.NET MAUI 9: Compiled bindings can be used with C# markup #2304

Open davidbritch opened 1 month ago

davidbritch commented 1 month ago

In .NET MAUI 9, compiled bindings can be used with C# markup (to replace reflection-based bindings with string paths).

Example:

// in .NET 8
MyLabel.SetBinding(Label.TextProperty, "Text");

// in .NET 9
MyLabel.SetBinding(Label.TextProperty, static (Entry entry) => entry.Text);

This new approach has several advantages:

More info: https://github.com/dotnet/maui/pull/21725

simonrozsival commented 3 weeks ago

Hopefully we will have a second related API to create compiled bindings in C#: https://github.com/dotnet/maui/pull/23239

BindingBase binding = Binding.Create(static (Entry entry) => entry.Text);