选中该复选框后,我希望能够获取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);
}
}
答案 0 :(得分: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);
}
}
}