locked
DatePicker control issue on Windows Phone 7 RRS feed

  • Question

  • Hi,
     Our datepicker control should be popuplated with current date when mobile page loads. For this we have set datepicker's "Value" property to DateTime.Now within "PhoneApplicationPage_Loaded" event. Now when page loads datepicker control is populated with current date time. But now when user click's the datepicker control to change current date time a default page is loaded and here we edit the date (and this is the defualt behaviour). But here the issue is, when the datepicker edit page is unloaded, again "PhoneApplicationPage_Loaded" event is executed and this makes datepicker's "Value" property to DateTime.Now, overriding newly edited datetime.
    How can we work on this resolve this issue.
    
    regards
    Sreejith
    
    Monday, November 15, 2010 4:38 AM

Answers

  • When I put a datepicker control on a form, it already sets the date to Today's date.  I double checked and ran the app, and today's date is already selected.

    Apparently Page_Loaded is fired everytime you use the DatePicker, so you could put it in the constructor if you really need to set the date.

            // Constructor  
            public PhoneApplicationPage()  
            {  
                InitializeComponent();  
                DatePicker1.Value = DateTime.Now;  
            } 
    Monday, November 15, 2010 4:52 AM

All replies

  • Hi Sreejith,

    Can you just do the default assignment only when the doesn't have a value yet?

    ps - People have been experiencing an issue with new forum profiles. You may find it helpful to know you can retain formatting by wrapping content with <pre></pre> (ty Joel) or you can set your Editor to Rich Text in your profile if you wanted to control your formatting.
    Monday, November 15, 2010 4:42 AM
  • When I put a datepicker control on a form, it already sets the date to Today's date.  I double checked and ran the app, and today's date is already selected.

    Apparently Page_Loaded is fired everytime you use the DatePicker, so you could put it in the constructor if you really need to set the date.

            // Constructor  
            public PhoneApplicationPage()  
            {  
                InitializeComponent();  
                DatePicker1.Value = DateTime.Now;  
            } 
    Monday, November 15, 2010 4:52 AM