Hello,
if you have multiple parameters like PackageID and PackageName, does this. mean you have to create another method for every parameter?
You can create an object with PackageID and PackageName attributes. then send this object by QueryProperty
.
For example, I create a Package
class.
public class Package
{
public string packageId { get; set; }
public string packageName { get; set; }
}
Then I send this object by Dictionary
in the GoTapGestureRecognizer_Tapped
method.
async void GoTapGestureRecognizer_Tapped(object sender, EventArgs e)
{
Label lbl = (Label)sender;
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. Please notice I change the property in QueryProperty
and MyPage2.cs
like the following 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");
}
}
You can refer to this document about Pass data
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.