For some reason this event fires twice. The other events I have on button clicks for example only fires once, but the date change on the date picker for what ever reason fires twice in a row.
Any ideas?
Code
public event EventHandler<CalendarEvent开发者_开发知识库Args> DateTimeStartChanged;
private void dateTimeStart_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
if (!_loading)
{
e.Handled = true;
if (DateTimeStartChanged != null)
if (dateTimeStart.SelectedDate != null && dateTimeEnd.SelectedDate != null)
{
StartDate = (DateTime) dateTimeStart.SelectedDate;
DateTimeStartChanged(this,
new CalendarEventArgs((DateTime) dateTimeStart.SelectedDate,
(DateTime) dateTimeEnd.SelectedDate));
}
}
}
What a frustrating issue. My workaround for this issue was as follows. Has worked so far. Hope this helps someone.
private DateTime? currentDateTime = null;
private void dpDate_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
if(currentDateTime != dpDate.SelectedDate)
SaveData();
currentDateTime = dpDate.SelectedDate;
}
It's a bug with the DatePicker control, and not your issue. Unfortunately there isn't much you can do about it except apply a workaround such as setting a flag so it only executes the first time.
精彩评论