Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET MAUI 9: Compiled bindings #2427

Closed
davidbritch opened this issue Aug 7, 2024 · 0 comments · Fixed by #2524
Closed

.NET MAUI 9: Compiled bindings #2427

davidbritch opened this issue Aug 7, 2024 · 0 comments · Fixed by #2524
Assignees
Labels
🏁 Release: .NET 9 Work items for the .NET 9 release doc-enhancement Improve the current content [org] 📌 seQUESTered Identifies that an issue has been imported into Quest. resolved-by-customer Indicates issues where the customer no longer needs any help. [org]

Comments

@davidbritch
Copy link
Contributor

davidbritch commented Aug 7, 2024

In .NET MAUI 9 there's a source generator that allows developers to call the SetBinding extension method to define bindings on their bindable objects using Func instead of string paths. There's also an additional API that builds on this that will not only set the binding directly to the object, but it will return the binding object instance and allow the developer to pass it to some other method and use it later.

This approach is required instead of string-based bindings in NativeAOT apps, and in apps with full trimming enabled.

String-based binding in code:

label.BindingContext = new PageViewModel { Customer = new CustomerViewModel { Name = "John" } };
label.SetBinding(Label.TextProperty, "Customer.Name");

Compiled binding in code:

label.SetBinding<PageViewModel, string>(Label.TextProperty, static vm => vm.Customer.Name);
// or with type inference:
label.SetBinding(Label.TextProperty, static (PageViewModel vm) => vm.Customer.Name);

Compiled binding in XAML:

<Label Text="{Binding Customer.Name}" x:DataType="local:PageViewModel" />

Will also need to update the compiled bindings doc.

More info: dotnet/maui#23239


Associated WorkItem - 314392

@davidbritch davidbritch added the 🏁 Release: .NET 9 Work items for the .NET 9 release label Aug 7, 2024
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Aug 7, 2024
@davidbritch davidbritch self-assigned this Sep 17, 2024
@davidbritch davidbritch added the doc-enhancement Improve the current content [org] label Sep 17, 2024
@davidbritch davidbritch added the 🗺️ reQUEST Triggers an issue to be imported into Quest. label Sep 17, 2024
@sequestor sequestor bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels Sep 17, 2024
@davidbritch davidbritch moved this from 🔖 Ready to 🏗 In progress in dotnet/docs-maui 2024 Sprints Sep 26, 2024
@dotnetrepoman dotnetrepoman bot added the resolved-by-customer Indicates issues where the customer no longer needs any help. [org] label Sep 30, 2024
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in dotnet/docs-maui 2024 Sprints Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏁 Release: .NET 9 Work items for the .NET 9 release doc-enhancement Improve the current content [org] 📌 seQUESTered Identifies that an issue has been imported into Quest. resolved-by-customer Indicates issues where the customer no longer needs any help. [org]
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants