2014-03-13 33 views
1

當複選框被選中時,我希望能夠獲取datepicker/timepicker的值。會發生什麼是它能夠獲得該值,但是當我嘗試更改該值時,它不會更改,因爲它只會返回到以前的值。我做錯了什麼?以下是我的代碼:OnNavigateTo更改日期/時間選擇器值 - windows phone

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); 
     } 
    } 
+0

OnNavigatedTo對於數據選擇器和時間選項卡上設置的每個值都是免費的禮物。 –

回答

2

當您嘗試更改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); 
     } 
     } 
    } 
+0

感謝您的回覆。我已經嘗試過,是的,現在正在工作。非常感謝! –