【问题标题】:OnNavigateTo change date/time picker value- windows phoneOnNavigateTo 更改日期/时间选择器值 - windows phone
【发布时间】:2014-03-13 06:29:30
【问题描述】:

当复选框被选中时,我希望能够获取 datepicker/timepicker 的值。发生的事情是它能够获取该值,但是当我尝试更改该值时,它不会更改,因为它只会返回到以前的值。我做错了什么?以下是我的代码:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);


        if (NavigationContext.QueryString.ContainsKey("Id"))
        {
            Id.Text = NavigationContext.QueryString["Id"];

        }


        ScheduledAction currentReminder = ScheduledActionService.Find(NavigationContext.QueryString["Id"]);

        if (currentReminder == null)
        {
            cBox.IsChecked = false;

        }
        else 
        {
            cBox.IsChecked = true;
            rrDate.Value = currentReminder.BeginTime;
            hiddenTime.Text = rrDate.Value.ToString();
            rrTime.Value = DateTime.Parse(hiddenTime.Text);
        }
    }

【问题讨论】:

  • OnNavigatedTo call 是对 datpickers 和 timepickers 上设置的每个值的免费礼物。

标签: c# windows-phone-7 windows-phone-8 datepicker timepicker


【解决方案1】:

当您尝试更改 datepicker 值时,页面 OnNavigatedTo 事件每次都会触发。这是解决方案,希望对您有所帮助。

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
  if(e.NavigationMode!=NavigationMode.Back)
    {
        if (NavigationContext.QueryString.ContainsKey("Id"))
        {
            Id.Text = NavigationContext.QueryString["Id"];

        }
        ScheduledAction currentReminder = ScheduledActionService.Find(NavigationContext.QueryString["Id"]);
        if (currentReminder == null)
        {
            cBox.IsChecked = false;
        }
        else 
        {
            cBox.IsChecked = true;
            rrDate.Value = currentReminder.BeginTime;
            hiddenTime.Text = rrDate.Value.ToString();
            rrTime.Value = DateTime.Parse(hiddenTime.Text);
        }
      }
    }

【讨论】:

  • 感谢您的回复。我已经尝试过了,是的,它现在正在工作。非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-03
  • 1970-01-01
  • 1970-01-01
  • 2015-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多