We help IT Professionals succeed at work.

WP7 DatePicker returns to original value after edit

Medium Priority
Last Modified: 2014-11-12
I have a page in my WP7 app that allows the user to add or edit a date.  I use the DatePicker control from the WP7 Toolkit referenced here : http://windowsphonegeek.com/articles/wp7-datepicker-and-timepicker-in-depth--api-and-customization.  When I add a date everything works fine and the date is added successfully.  

The problem comes when I try to edit that date.  

The process that I use is as follows:
When the page loads, I look for an edit value sent to it.  IF the edit value is sent, then I set the DatePicker to the original date which I look up in the underlying class:

datePicker1.value = originalDate

The DatePicker control gets the correct value and displays it.  When I select the field again the full screen selection choice shows up, and I can edit the date.  However when I click 'Save' and it reloads the screen that the control is on, the control is set back to the original date -- not the modified date.  

I am using the same process to change other fields -- names, addresses, etc. and don't have any problems with them.  Only the Datepicker control is causing a problem  
Watch Question


do you have the date set in the xaml?


no -- the date is only set by that line of code that I put in the question.

the declaration of the date picker: <toolkit:DatePicker Name="datePicker1" Height="74" Width="179" Grid.Row="1" Grid.Column="1" />


which method calls "datePicker1.value = originalDate" ??  Is it on the PAge_Loaded event?


it is the OnNavigatedTo:

 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
            selectedItem = Convert.ToInt16(NavigationContext.QueryString["edit"].ToString());
            Person p = GetPersonFull(selectedItem);
            textName.Text = p.Name;
            datePicker1.Value = p.Birthdate;


Open in new window

I am thinking after reading your question that the problem is that the 'edit' parameter is being sent to the page that I am using after selecting the date from the popup page launched by the datepicker control.  

So I guess my question is, how do I prevent this?  I would rather not have to create a new control myself, since there is a control already out there that looks like it does what I need.  I don't know how to:

a: modify the second screen on the datepicker control,  

b) check for the prior page and add an exclusion to setting the value if the calling page was the datepicker page

c) remove the 'edit' parameter from being sent by the datepicker selection page

I would assume that any of those three would work, but I don't know the process for any of them.  

why are you reloading the screen after a save. Just have logic to load the data not the page after a save.


I am not loading the screen purposefully -- the control does that.  on the date picker control, when you select it to make a change it loads a new page.  I think that this page is re-calling my edit page which is reloading the original value.  

The control I am using is from the windows phone toolkit.  
Unlock this solution and get a sample of our free trial.
(No credit card required)


I can try that.  I am assuming there should be some way to handle this more natively than that though.  I may not fully understand what is happening -- it seems odd that the datepicker page would re-send the query to the source page.  


setting a flag worked -- I was already changing the PageTitle to say edit instead of add -- so looking for that change made all the difference.

I am still not sure why the Datepicker page is sending the query string again, but oh well!  

Thanks for the help.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.