Hello,
If you want to pass multiple parameters, you can send them by Dictionary
. Or create an object that contain these parameters. put this Object to the Dictionary
and send it, here is a similar thread: Passing Parameters using QueryParameter in MAUI.
Package package= new Package() { packageId = lbl.Text, packageName = "yourpageName" };
var navigationParameter = new Dictionary<string, object> { { "MyPackage", package } };
await Shell.Current.GoToAsync($"MyPage2", navigationParameter);
You can get this object in the MyPage2's background code.
[QueryProperty(nameof(MyPackage), "MyPackage")]
public partial class MyPage2 : ContentPage
{
public Package MyPackage
{
set
{
ShowMessage(value);
}
}
public MyPage2()
{
InitializeComponent();
}
public async void ShowMessage(Package package)
{
var id = package.packageId;
var name = package.packageName;
await DisplayAlert("Query", id+ name, "Ok");
}
}
If you want to get these parameters in the ViewModel, you need to achieve IQueryAttributable
interface and get parameters in the ApplyQueryAttributes
method.
public class Page2ViewModel : IQueryAttributable
{
public void ApplyQueryAttributes(IDictionary<string, object> query)
{
Package myPackage= query["MyPackage"] as Package;
var id= myPackage.packageId;
var packageName= myPackage.packageName
}
}
Here is a document about passing and processing multiple items of data in shell with QueryProperty
.
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.