简体   繁体   English

在整个类中使用LoadStateEventArgs e

[英]Use LoadStateEventArgs e in whole the whole class

I am an beginner in making a Windows store app. 我是制作Windows应用商店应用程序的初学者。 this app is based on C# and XAML. 该应用程序基于C#和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: 在第二页上,我检索了groupId中给出的UniqueId,如下所示:

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. 现在,我想在整个页面中使用uniqueId。 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. 有两种方法可以执行此操作:仅为Page中的UniqueId创建一个类变量,或将值存储在某个位置,例如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! 希望这对您有所帮助,并祝您编程愉快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM