-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Binding SG] Add an API for creating instances of TypedBinding #23239
[Binding SG] Add an API for creating instances of TypedBinding #23239
Conversation
a75ab00
to
abd3426
Compare
|
||
namespace Microsoft.Maui.Controls | ||
{ | ||
public static class BindingFactory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@StephaneDelcroix what do you think about just putting the method here on Binding
?
…factory-generated-bindings-api
…factory-generated-bindings-api
…factory-generated-bindings-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reran some tests, as I think the Xcode provisionator failures are fixed now.
/// <param name="targetNullValue">The value to supply for a bound property when the target of the binding is <see langword="null" />.</param> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCodeMessage", | ||
Justification = "The Binding.Create<TSource, TProperty>() method does not create an instance of Binding but an instance of TypedBinding<TSource, TProperty>.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like there might be mixed tabs/spaces in this file.
This comment was marked as outdated.
This comment was marked as outdated.
Having a Binding.Create() method allows the capture of the binding, and potentially a reuse of it, which isn't supported. I would stick with SetBinding... |
@StephaneDelcroix I think the three examples are |
Description of Change
We recently enabled a source generator that allows developers to call the
SetBinding
extension method to define bindings on their bindable objects usingFunc
instead of string paths. This PR builds on top of that feature and adds a second supported API 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.Use-cases
1. Setters
Before:
maui/src/Controls/src/Core/Shell/BaseShellItem.cs
Lines 429 to 433 in 0572098
After:
2.
DataTrigger
:Before:
maui/src/Compatibility/ControlGallery/src/Issues.Shared/Bugzilla57910.cs
Lines 60 to 61 in c564156
After:
3.
MultiBinding
Before:
maui/src/Controls/tests/Core.UnitTests/MultiBindingTests.cs
Lines 68 to 78 in c564156
After:
Issues Fixed
Contributes to #22384
/cc @jkurdek @StephaneDelcroix @jonathanpeppers