Search code examples
navigationpopupmaui

How to pass data with ShowPopupAsync in .NET MAUI from calling ViewModel to Popup VieModel?


I tried to follow the Microsoft tutorial on passing data from the calling ViewModel to the Popup ViewModel on the following website: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/views/popup

Nonetheless, I don't understand exactly how I can pass data. My question: Does anybody know, how I may pass e.g. string or integer data? Do I need to use ApplyQueryAttributes?

I thought I could pass data like similar when using NavigateToAsync with QueryAttributes, e.g. NavigationService.NavigateToAsync($"DestinationView?userId={User.ID}"); but it does not seem that trivial.

How may I perform that?


Solution

  • this is covered in the docs

    this.popupService.ShowPopup<MyPopupViewModel>(onPresenting: viewModel => viewModel.CallSomeMethod(10));
    

    or

    this.popupService.ShowPopup<MyPopupViewModel>(onPresenting: viewModel => viewModel.SomeProperty = 10);