I am an beginner in making a Windows store app. this app is based on C# and XAML. On the first page the data is send to the second page on the press off a tile. It will give a parameter to the second page like this:
void ItemView_ItemClick(object sender, ItemClickEventArgs e)
{
var groupId = ((ProductGroup)e.ClickedItem).UniqueId;
this.Frame.Navigate(typeof(GroupView), groupId);
}
on the second page i retreive the UniqueId given in the groupId like this:
private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
string uniqueId = ((string)e.NavigationParameter);
var result = await backEnd.getJsonData(uniqueId);
this.DefaultViewModel["Groups"] = result;
}
Now i want to use the uniqueId in this whole page. Does anyone know how to do it?
Thanks in advance!
There are two ways you can do this: Create a class variable just for the UniqueId in your Page, or store the value somewhere, such as your ViewModel.
Try this:
private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
string uniqueId = ((string)e.NavigationParameter);
var result = await backEnd.getJsonData(uniqueId);
this.DefaultViewModel["Groups"] = result;
this.DefaultViewModel["UniqueId"] = uniqueId;
}
Then, whenever you need to go back and get it, just use:
this.DefaultViewModel["UniqueId"];
Hope this helps and happy coding!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.