[BUG] EventToCommandBehavior is not working in v10
egvijayanand opened this issue · 4 comments
Is there an existing issue for this?
- I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
When mapped, the UI event invokes the MVVM Command. It works fine in v9.1.1, but with v10, it reaches the converter part and then stops responding.
Expected Behavior
Same functionality as v9.1.1
Steps To Reproduce
- Clone the GitHub repo.
- Currently referencing v9.1.1 of the Toolkit Package.
- Build and launch the app.
- It will have two text fields on either side.
- EventToCommandBehavior is integrated when a message is sent from HybridWebView (HTML control) to MAUI.
- Type some text and click the
Send to .NET
button. - The message will reach the MAUI side.
- Now upgrade to v10 and repeat steps 3 to 7. It's not working.
Link to public reproduction project repository
https://github.com/egvijayanand/toolkit-issue-2391
Environment
- .NET MAUI CommunityToolkit: v10
- OS: Windows 11 (10.0.26100.2605)
- .NET MAUI: 9.0.21
Anything else?
v9.1.1 works fine.
The sample project to simulate this issue is here.
My bad, I misread the fine print in the changelog. Got overlapped with the BaseConverter
changes.
.NET MAUI Behaviors do not automatically inherit their parent's BindingContext (a breaking change from Xamarin.Forms)
I'm not fully aware of the reasoning behind this design change, but ideally, it should have been put under a flag with the default value now set to false.
In this EventToCommandBehavior scenario, it won't work without its BindingContext set. Simply toggling a flag would be better than tinkering the Source for the Command bound to the behavior.
Hey Vijay! Yup - this is a breaking change in CommunityToolkit.Maui v10.0.0
.
You can find more information, including a working solution, here on StackOverflow: https://stackoverflow.com/a/79099574/5953643
We're also included this as a Breaking Change in our release notes:

Thanks for the detailed info.
Have logged a proposal in the MAUI repo for an elegant solution (resolving it relatively is one such option) rather than working with a named Binding source which is always a trouble while refactoring.