[英]Pass parameter value from one function to another in C#
The following function contains a navigation parameter that represents a value passed from the previous page 以下函数包含一个导航参数,该参数表示从上一页传递的值
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
is a class that contains the items to always be passed when navigating between pages. QuizArgs
是一个类,其中包含在页面之间导航时始终传递的项目。
class QuizArgs
{
public string sector;
public int Total;
public int question;
public string type;
}
I want to use the Object navigationParameter
value from the LoadState
function in the click function. 我想在click函数中使用
LoadState
函数中的Object navigationParameter
值。
I want to assign sector
to the value in the navigation parameter instead of string "nav". 我想将
sector
分配给导航参数中的值,而不是字符串“ nav”。
How do I do use args.sector
in the click function? 如何在点击功能中使用
args.sector
?
Check this: 检查一下:
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);
}
}
您可以将args声明为global。然后两个函数都可以使用args。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.