-
Notifications
You must be signed in to change notification settings - Fork 36
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
[BUG] Typed bindings is not working as expected. #272
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Here's the GitHub repository with the sample app Kindly let me know if I missed anything, as a last measure even tried using Two-way binding, but no change in the output. It's not only to Picker as have tried with another sample that hosts a variety of controls, nothing is working after updating to Typed bindings. |
Hey Vijay! It looks like you've only implemented a One-Way Typed Binding. You've bound the getter of You just need to add this as the setter for your Typed Binding: static (MainViewModel vm, int index) => vm.Index = index One-Way Binding (Read-Only) new Picker()
.Bind(Picker.ItemsSourceProperty,
static (MainViewModel vm) => vm.Numbers)
.Bind(Picker.SelectedIndexProperty,
static (MainViewModel vm) => vm.Index,
mode: BindingMode.TwoWay), Two-Way Binding (Read-Write) new Picker()
.Bind(Picker.ItemsSourceProperty,
static (MainViewModel vm) => vm.Numbers)
.Bind(Picker.SelectedIndexProperty,
static (MainViewModel vm) => vm.Index,
static (MainViewModel vm, int index) => vm.Index = index,
mode: BindingMode.TwoWay), Example App Running Fixed Code |
I'd love your help updating our docs to make this more clear! Or point me to whatever resource where you were learning Typed Bindings and we'll see if we can update that 💯 |
I understand @brminnick, may be an understanding gap. Thanks. But definitely feel it's an overhead, as most of the time we work with two-way data-binding and it writes back to the same property from where the read happens. Is there a way to automate things so that we need to write the explicit setter only if there's logic involved? |
Yup - this is the biggest difference between the previous way of declaring bindings and Typed Bindings.
It may be possible. It'd require a lot of forethought and unit testing to make sure we don't break any default behavior, though; I'm not sure if the If you want to try it out feel free to submit a New Feature Proposal. |
Not fully sure, but seems possible. Let me try with a sample and get back on this. |
Awesome! Yea, we'll want to test the new implementation against one-way bindings, two-way bindings, one-way-to-source bindings and one-time bindings. There's also a
|
I'm a big fan of DefaultBinding (both property and mode). Last time when TypedBinding was in prototype, I asked for the possibility of having this in the context of typed too. Like Text property being the default for Label/Entry and so on and those are two-way too. Let me check the implementation to validate the possibility. |
For picker, SelectedIndex is default and two-way, that's why I didn't check it in deep. Thought mapping itself is good enough to do a two-way binding and that's the reason tried to set the binding mode to two-way explicitly. |
Looks like, have cracked it. I've already tried this. But just missed a single change while parsing the Func expression that made me to hold that for so long. Instead of adding a generic parameter, have assumed the return value of the Func expression as an object. Now have included that one. This will work for default properties too :-) Will add the extension methods to the same sample, publish a newer version, and will give an update. |
Have pushed the updated version. Have suffixed the Bind methods with v2 as the parameter types clash with those from the package. The method that parses the Property name from the LINQ expression definitely requires refactoring as it was written years ago. @brminnick Let me know your thoughts on this. |
No way! That was quick!! Where can I find the code? |
Same repo. Just pull the latest version.
Regards,
Vijay Anand E G
…________________________________
From: Brandon Minnick ***@***.***>
Sent: Wednesday, November 29, 2023 10:24:19 AM
To: CommunityToolkit/Maui.Markup ***@***.***>
Cc: Vijay Anand E G ***@***.***>; Author ***@***.***>
Subject: Re: [CommunityToolkit/Maui.Markup] [BUG] Typed bindings is not working as expected. (Issue #272)
No way! That was quick!!
Where can I find the code?
—
Reply to this email directly, view it on GitHub<#272 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ATRGWDB5OJEY5D64HFNWBRTYG25XXAVCNFSM6AAAAAA76SNMJ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZRGIYTMMBUGQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Further discussion here - #343 |
Is there an existing issue for this?
Did you read the "Reporting a bug" section on Contributing file?
Current Behavior
Typed binding breaks the working behavior of the controls, whereas classic binding works in the way it is designed.
Expected Behavior
Like how it works in classic binding, only the approach changes with improved type safety.
Steps To Reproduce
Link to public reproduction project repository
https://github.com/egvijayanand/markup-issue-272
Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: