How to use PopupService
to show popup in ViewModel
?
I have ViewModel
with:
[RelayCommand]
private async Task ShowPopupAsync(object sender)
{
var popup = popUpService.GetPopup(sender);
popupService.ShowPopup(popup);
}
PopUpService:
public Popup GetPopup(object sender)
{
var button = sender as ImageButton;
var popup = new CustomPopup
{
Anchor = button
};
return popup;
}
And I have error in line popupService.ShowPopup(popup);
:
System.Collections.Generic.KeyNotFoundException: 'The given key 'CommunityToolkit.Maui.Views.Popup' was not present in the dictionary.'
When I use Shell.Current.ShowPopup(popup);
everything works but I don’t want to use Shell
in my ViewModel
.