WPF Management Event for Users

For some reason, this event fires twice. Other events that I have when I click the button, for example, fire only once, but the date in the date picker changes by what it ever causes twice in a row.

Any ideas?

code

public event EventHandler<CalendarEventArgs> 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)); } } } 
+4
source share
2 answers

What an unpleasant problem. My workaround for this question was as follows. Still worked. Hope this helps someone.

 private DateTime? currentDateTime = null; private void dpDate_SelectedDateChanged(object sender, SelectionChangedEventArgs e) { if(currentDateTime != dpDate.SelectedDate) SaveData(); currentDateTime = dpDate.SelectedDate; } 
+1
source

This is a bug with the DatePicker control, not your problem. Unfortunately, you can do nothing with this, except to apply a workaround, for example, set the flag so that it runs only for the first time.

0
source

Source: https://habr.com/ru/post/1339789/


All Articles