-
Notifications
You must be signed in to change notification settings - Fork 416
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] IPopupService.ShowPopup(new ViewModel) doesn't assign viewmodel to popup BindingContext #1524
Comments
@brminnick it only took 14 days for someone to request this 😂 |
Hi @GuidoNeele! The good news is that you're experiencing the expected behavior; Looking at the PR you've submitted, you are assigning the
Can you help me understand your expectation? Is it written in our documentation that I strongly feel that it is out-of-scope for That being said, I'm happy to be proven wrong. If there are existing examples where a Dependency Injection library has similar behavior, please do share them. |
I'm sorry Brandon, but I feel your comment is a bit strange and trying to send me into the woods. It's clear by Shawn's previous comment that you already internally have discussed this or something like it. I somewhat understand what your stance is but I don't see any problem with the issue I opened or the pull request I proposed. The main problem here is that the PopupService is exposing 2 methods which require newing up an instance of a view model. They are not asking for a Type, they are asking for an object. The question is how can I not expect that object to be attached to the popups BindingContext? Why else would I create that object? |
Yes, we did have a previous conversation, and I'm looking for more examples and evidence. The implementation in your PR breaks the Single Responsibility principle of
Quick correction - they don't require newing up an instance of a view model. You should only be using Looking at your sample code, you are using the incorrect I've annotated the code in my PR to help explain the differences between the two |
Is adding an IoC-style factory function for a popup configuration - also no-go? Like this:
|
I just thought the reason I am asking is not clear... When you run ShowPopupAsync() via IPopupService, you don't have access to the instance of the Popup. As such, you are crippled because you can't show popups that have to be closed by the caller. Use case: some background task wants to kill 'loading' popup spinner when its, in fact, done loading. No, adding 'All done please press one more button' is not a good UI. |
Example of the code that doesn't work
|
You aren't crippled, we just haven't made that part any easier for you yet. You can follow this approach which fires an event: Note the above example also shows how to assign the BindingContext which I have seen you ask somewhere. For the ability to close a Popup from the caller, we do have a PR open for that and are just working through testing it. This it the PR #1688 |
Is there an existing issue for this?
Did you read the "Reporting a bug" section on Contributing file?
Current Behavior
The viewmodel in this snippet of code is not assigned to the popup which you would expect if you create the viewmodel yourself.
Maui/src/CommunityToolkit.Maui/PopupService.cs
Lines 59 to 68 in d00c4a0
Expected Behavior
When using ShowPopup(new ViewModel()) I expect the passed instance of ViewModel to be assigned to the BindingContext of the newly created popup.
Steps To Reproduce
PopupService.AddTransientPopup<MyPopup, MyViewModel>(services);
Link to public reproduction project repository
https://github.com/GuidoNeele/mct_popupservice_issue
Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: