Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Created Unassigned: DateTimePicker is causing OnValueChanged to be raised twice [22014]

$
0
0
This is not my original bug but in answer to a question that was raised on StackOverflow, I have reproduced it with the attached stack traces.

The __OnValueChanged__ event is being routed from both the __DateTimePicker__ and the __TimePicker__ objects. Changing to use binding corrects the issue but I suspect this is because data binding always checks if the value has actually changed before trying to change it again.

The reason for this appears to be is because there is a __TimePicker__ embedded within the __DateTimePicker__ to provide the functionality. Unfortunately, both __DateTimePicker__ and __TimePicker__ derive from the same base and thus raise the same routed event within __UpDownBase<T>__ where T is __DateTime?__.

if you check on the event arguments, __e.RoutedEVent__ is always __UpDownBase<DateTime?>.OnValueChanged__ since this is the class raising the event. __e.Source__ or __e.OriginalSource__ is always the __DateTimePicker__ itself.

There is code within __DateTimeUpDown.RaiseValueChangedEvent()__ to check if the TemplatedParent is a __TimePicker__ with a TemplatedParent of a __DateTimePicker__ to prevent re-raising but whether the event is raised from the __DateTimePicker__ or the __TimePicker__ the TemplatedParent always seems to be the __DateTimePicker__ so that fails thus you get the event twice.

Viewing all articles
Browse latest Browse all 4964

Trending Articles