Hello,
If you want to transfer ID to ViewModel of navigated page. You can use Process navigation data using a single method to achieve it.
Firstly, please add Id when you navigated page.
private async void OnSave(object obj)
{
string Id = "42";
await Shell.Current.GoToAsync($"{nameof(NoticeBoardEditPage)}?Id={Id}");
}
Then, please remove _Id in your NoticeBoardEditPageViewModel constructor like this code BindingContext = new NoticeBoardEditPageViewModel();
In the end. Navigation data can be received by implementing the IQueryAttributable interface on the NoticeBoardEditPageViewModel.
public class NoticeBoardEditPageViewModel : IQueryAttributable
{
public NoticeBoardEditPageViewModel()
{
}
public void ApplyQueryAttributes(IDictionary<string, string> query)
{
//get the Id here.
string id = HttpUtility.UrlDecode(query["Id"]);
int ID= int.Parse(id);
}
}
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.