Passing values from page to page
When navigating from one page to another, you’ll often want to pass in a value. There are a few ways to do this; here are the two most common:
- Using the
url (?)
syntax as you might with a URL to navigate to a page on the web - Using navigation parameters with a dictionary
Passing values with the url (?) syntax
Let’s return to the Buddies
page. Right now, the Button
has a GoToDetailsCommand
command. But the Details page needs to know which Buddy to show details about.
We’ll modify RelayCommand
in ViewModel
to pass in BuddyId
. To make this work, we need a Buddy
object (which will have the Id
). However, Buddy is just one of the types of users of this program, so let’s start by defining the User
type:
[ObservableObject] public partial class User { [ObservableProperty] private string name; [ObservableProperty] [1] ...