How do you get DatePicker to show the initial date correctly

Lloyd Sheen 1,476 Reputation points
2024-01-29T18:07:54.3733333+00:00

Pretty much as in the title. The display on the DatePicker is the 1900 date. In the documentation it says the initial date is DateTime.Now but when it displays it shows 1900-01-01. If you query the value it is correct. So it works correctly but shows the user the incorrect info. I have searched all over and I can see others complaining buy MS just says it has been resolved. I guess the resolution is not to use the DatePicker.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,231 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Albert Kallal 5,231 Reputation points
    2024-01-29T19:37:07.47+00:00

    Hum, what version of Maui? with .net core 8 version, (latest)? If I drop in a date control, say like this:

            <DatePicker
                x:Name="MyDate"/>
    
    

    And then run, for windows app, I get/see this: User's image

    And if I run as android (emulator), then I get this: User's image

    So, the date picker will default as today's date, but that assumes the date picker is un-bound (does not have a Binding expression. So, you may well have to provide a bit more markup, but out of the box, the above shows the DatePicker does default to today for the default date. If you have a binding expression, then of course the date will come from the data source being used, and if null, then of course you get the 1900 date value.