date picker weird dates and space

Eduardo Gomez 4,156 Reputation points
2023-05-31T13:01:32.0766667+00:00

Hello.

I am using datepicker in a wpf app but is weird. For example: it doesn't show 1,2,3,4,5 etc.

It shows 31 (todays date), 10, 28 etc

User's image

also, there is a weird black space un the data picker

        <DatePicker
            Margin="0,10,0,0"
            ui:ControlHelper.PlaceholderText=""
            DisplayDateStart="{x:Static sys:DateTime.Now}"
            FocusVisualStyle="{x:Null}"
            Validation.ErrorTemplate="{x:Null}" />
Developer technologies | Windows Presentation Foundation
{count} votes

Answer accepted by question author
  1. Hui Liu-MSFT 48,711 Reputation points Microsoft External Staff
    2023-06-06T07:49:21.7766667+00:00

    Hi,@Eduardo Gomez. I tested your code and reproduced the problem. For displaying previous dates, You could update the code as below.

    
    <DatePicker
                Margin="0,10,0,0"
                ui:ControlHelper.PlaceholderText=""
              
                FocusVisualStyle="{x:Null}"
                SelectedDate="{Binding examDetail.Date, UpdateSourceTrigger=PropertyChanged}"
                Validation.ErrorTemplate="{x:Null}" />
    

    SelectedDate: Binds the selected date of the DatePicker to the "Date" property of the "examDetail" object. The UpdateSourceTrigger=PropertyChanged part indicates that the binding source should be updated when the DatePicker's selected date changes.

    The result:

    User's image

    Update: : I put the code DatePickerExtensions under the ExamDetailDialogViewModel class.

      <DatePicker
                Margin="0,10,0,0"
                ui:ControlHelper.PlaceholderText=""
              dialogs:DatePickerExtensions.DisallowPastDates="True"
                FocusVisualStyle="{x:Null}"
                SelectedDate="{Binding examDetail.Date, UpdateSourceTrigger=PropertyChanged}"
                Validation.ErrorTemplate="{x:Null}" >
    
    
    
      public static class DatePickerExtensions
        {
            public static readonly DependencyProperty DisallowPastDatesProperty =
                DependencyProperty.RegisterAttached("DisallowPastDates", typeof(bool), typeof(DatePickerExtensions), new PropertyMetadata(false, OnDisallowPastDatesChanged));
    
            public static bool GetDisallowPastDates(DatePicker datePicker)
            {
                return (bool)datePicker.GetValue(DisallowPastDatesProperty);
            }
    
            public static void SetDisallowPastDates(DatePicker datePicker, bool value)
            {
                datePicker.SetValue(DisallowPastDatesProperty, value);
            }
    
            private static void OnDisallowPastDatesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                if (d is DatePicker datePicker)
                {
                    if ((bool)e.NewValue)
                    {
                        datePicker.BlackoutDates.Add(new CalendarDateRange(DateTime.MinValue, DateTime.Today.AddDays(-1)));
                    }
                }
            }
        }
    

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.