如何在前后导航时保存单选按钮选择?
对于文本框,我知道它是这样的:
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
if (e.PageState != null)
{
this.text5_input.Text = e.PageState["txtContents"] as string;
}
}
private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
e.PageState["txtContents"] = this.text5_input.Text;
}
然而,当我们使用类似的单选代码按钮时,会弹出一个错误,指出无法将字符串(e.PageState)转换为bool(单选按钮)。
我该如何实现?
答案 0 :(得分:1)
您可以使用RadioButtonInstance.IsChecked.ToString并恢复数据使用bool.Parse((bool)e.PageState [" rbState"])
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
if (e.PageState != null)
{
this.text5_input.Text = e.PageState["txtContents"] as string;
this.RadioButtonInstance.IsChecked = (bool)e.PageState["rbState"];
}
}
private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
e.PageState["txtContents"] = this.text5_input.Text;
e.PageState["rbState"] = this.RadioButtonInstance.IsChecked;
}
理论上这是为了布尔,你能试试吗?