Skip to content

Open popup from view model #566

Closed Answered by kphillpotts
imsam67 asked this question in Q&A
Aug 24, 2022 · 3 comments · 4 replies
Discussion options

You must be logged in to vote

I think it depends on how much of an MVVM-Purist™ you are. 😉 I'm a pragmatist, so personally I'd be more than happy to go with the approach suggested by @VladislavAntonyuk.

But if you are a purist and want to decouple UI elements from your ViewModels then another option would be to create a IPopupService which you inject into your ViewModels. Something like this:

create interface

public interface IPopupService
{
	void ShowPopup(Popup popup);
}

create implementation

public class PopupService : IPopupService
{
	public void ShowPopup(Popup popup)
	{
		Page page = Application.Current?.MainPage ?? throw new NullReferenceException();
		page.ShowPopup(popup);
	}
}

don't forget to register it

ser…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@VladislavAntonyuk
Comment options

@imsam67
Comment options

@bijington
Comment options

@kphillpotts
Comment options

Answer selected by imsam67
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants