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:
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.