Hello,
Welcome to our Microsoft Q&A platform!
When you used the following code to pass parameter to next page
ItemDetailPage` ,
await Shell.Current.GoToAsync($"itemdetails?name={selectedCategoryId}");
We could get the passed data by using QueryProperty
to get the data in next page ItemDetailPage
, and we should add a default constructor for Page ItemDetailPage
,for example:
[QueryProperty(nameof(ProductCategoryId), "name")]
public partial class ItemDetailPage : ContentPage
{
public string ProductCategoryId
{
set
{
LoadData(value);
}
}
void LoadData(string id)
{
try
{
Console.WriteLine(" the passed data ProductCategoryId = " + id);
// set BindingContext for you page
}
catch (Exception)
{
Console.WriteLine("Failed to load animal.");
}
}
public ItemDetailPage()
{
InitializeComponent();
//BindingContext = new ItemDetailViewModel();
}
}
For more details, you can check: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation#pass-data
You can also refer to the sample :https://github.com/xamarin/xamarin-forms-samples/blob/master/UserInterface/Xaminals/Xaminals/Views/CatDetailPage.xaml.cs
Best Regards,
Jessie Zhang
---
If the response is helpful, please click "Accept Answer" and upvote it.
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.