以下函数包含一个导航参数,该参数表示从上一页传递的值
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
QuizArgs args = navigationParameter as QuizArgs;
var SectorGroups = QuizDataSource.GetGroups(args.sector);
this.DefaultViewModel["Groups"] = SectorGroups;
}
void ItemView_ItemClick(object sender, ItemClickEventArgs e)
{
var itemId = ((QuizGroups)e.ClickedItem).UniqueId;
var sectorId = new QuizArgs
{
sector = "nav",
question = 2,
Total = 0,
type=itemId
};
this.Frame.Navigate(typeof(Quiz), sectorId);
}
QuizArgs
是一个类,它包含在页面之间导航时始终传递的项目。
class QuizArgs
{
public string sector;
public int Total;
public int question;
public string type;
}
我想在点击功能中使用Object navigationParameter
函数中的LoadState
值。
我想将sector
分配给导航参数中的值,而不是字符串“nav”。
如何在点击功能中使用args.sector
?
答案 0 :(得分:1)
检查一下:
public class YourClass: YourBaseClass
{
QuizArgs args = null;
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
args = navigationParameter as QuizArgs;
var SectorGroups = QuizDataSource.GetGroups(args.sector);
this.DefaultViewModel["Groups"] = SectorGroups;
}
void ItemView_ItemClick(object sender, ItemClickEventArgs e)
{
if(args == null)
throw new NullReferenceException();
var itemId = args.UniqueId;
var sectorId = new QuizArgs
{
sector = "nav",
question = 2,
Total = 0,
type=itemId
};
this.Frame.Navigate(typeof(Quiz), sectorId);
}
}
答案 1 :(得分:0)
您可以将args声明为global.Then应该可以在两个函数中访问args。