Skip to content

Better Solution #2

@Xynratron

Description

@Xynratron

Hi Skarzag,

I came across the same problem as you. Last Year I mentioned in the Toolkit Repo, to "maybe you can allow Viewmodels" - because if you passed a VM to the Service it would create a new one. "No, you have to use DI!" (I would call it stubborn or so)

The source showed, only the Toolkit works, you can't fork the code, cause WinUI had a InternalsVisibleTo Attribute for the Toolkit ;-(

And: there was a missconception of the developer for ViewModels: you allways had to create them via dependency injection...

Now I just begun to rewrite my code for the Popups V2, but I discoverd everything IPopupService is doing is a wrapper. So we can use the extension methods in IPopupService directly:

INavigation.ShowPopup(new myView(new myViewmodel))

See: https://github.com/CommunityToolkit/Maui/blob/main/src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs

Instead of a View you can also pass a ´MyView : Popup´, how to add a VM or something else is up to you.

Sure, only an example. Originally I used ACR.Userdialogs and I tried wo have a Service with IPopupService to emulate all my calls to ACR.UserDialogs. What a Pain! But now we can write a small simple service (like your MauiService) to build everything simplier. I need to try more like a Working-Service-Popup with Progress, but I think this will be more easier than in V1.

BTW: your DI-Solution is very nice!

Best Regards

Xynratron

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions