質問

When the check box is checked, I would want to be able to get the value of the datepicker / timepicker. What happens is that it was able to get the value, but when I am trying to change the value, it will not change as it will just return back to the previous value. What have i done wrong? Below is my code:

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);
        }
    }
役に立ちましたか?

解決

When you try to change datepicker value, page OnNavigatedTo event fire every time. Here is the solution, may this will help you.

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);
        }
      }
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top