Windows Store App c# XAML: NavigationHelper LoadState/SaveSt

本文关键字:NavigationHelper LoadState SaveSt XAML Store App Windows | 更新日期: 2023-09-27 18:05:56

在前后导航时如何保存单选按钮选择?

对于文本框,我知道它是这样的:

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;
    }

但是,当我们对单选按钮使用类似的代码时,会弹出一个错误,说不能将字符串(例如pagestate)转换为bool(单选按钮)。

我该怎么做?

Windows Store App c# XAML: NavigationHelper LoadState/SaveSt

您可以使用RadioButtonInstance.IsChecked.ToString和使用bool. parse ((bool) e.p ageestate ["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;
}

理论上这是bool,你能试试吗?

相关文章:
  • 没有找到相关文章