I am using a regular WPF Calendar (System.Windows.Controls.Calendar) in an MVVM application. The calendar shows a month at a time, and the user will pick a single day. The calendar shows a few days of the next month at the bottom, which is fine.
The problem is that if I pick a date from the next month (eg the 2nd of the next month) then Calendar first updates the data binding with this date, and then immediately updates it again with the 1st of the month!
This happens for all dates in the next month that I select.
The calendar's SelectedDate and DisplayDate properties are data bound to the view model's Date property.
<Calendar SelectedDate="{Binding Date}" DisplayDate="{Binding Date}" />
The view model looks like this
public class CalendarProblemDemoViewModel : INotifyPropertyChanged
{
private DateTime _date;
public CalendarProblemDemoViewModel()
{
_date = DateTime.Today;
}
public DateTime Date
{
get { return _date; }
set
{
_date = value;
Debug.Write($"new date {_date}\n");
OnPropertyChanged(nameof(Date));
}
}
// Note: other code omitted, see the github project
}
I don't understand why this is happening?
Date. Did you try and see ifSelectedDateis different thanDisplayDate? - Khalil Khalaf