I didn’t believe it when I read the user’s complaint…typing .123 in a bound WPF textbox displays .321! It’s fixed for now, but I wonder if this can be classified as a WPF bug?
The problem occurs when the text box is bound to an Entity Framework double field with the UpdateSourceTrigger binding mode set to PropertyChanged. With each number typed after the decimal the cursor moves back to just after the decimal point causing the backwards number. When I put the UpdateSourceTrigger back to it’s default of LostFocus the problem (understandably) goes away.
So, is this a bug? Is there a workaround that would allow UpdateSourceTrigger to be PropertyChanged when bound to a double field?
There is a reason that TextBox is set to
LostFocusand notPropertyChanged. When you bind this to an EF double, the validation can cause a reset of the value, which in turn can reset the cursor position.Making a TextBox behave correctly with
UpdateSourceTrigger.PropertyChangedrequires a fair amount of custom logic, as you need to track cursor positions in events prior to the binding update, and restore afterwards.I doubt this would be considered a bug, though, as WPF sets TextBox to
UpdateSourceTrigger.LostFocus. If the default was different, I would agree that this would be a bug – but given the default settings, I doubt the team would treat it as one.