Are the numbers displayed back?

I did not believe it when I read a user complaint ... type .123 in the associated WPF..321 text box! . This has been fixed, but I am wondering if it can be classified as a WPF error?

The problem occurs when a text field is anchored to a double Entity Framework field with the UpdateSourceTrigger binding mode set to PropertyChanged. With each number entered after the decimal point, the cursor goes back immediately after the decimal point, calling the return number. When I return the default UpdateSourceTrigger to LostFocus, the problem (understandably) disappears.

So is this a mistake? Is there a workaround that will allow UpdateSourceTrigger to be PropertyChanged when binding to a double field?

+5
source share
2 answers

There is a reason the TextBox is set to LostFocus, rather than PropertyChanged. When you bind this to a double EF, the check can cause a reset of the value, which in turn can reset the cursor position.

Properly creating a TextBox using UpdateSourceTrigger.PropertyChangedrequires a significant amount of custom logic, since you need to track the cursor position in events until the binding is updated and subsequently restored.

I doubt this will be considered a mistake, although WPF sets the TextBox to UpdateSourceTrigger.LostFocus. If the default value was different, I would agree that this would be a mistake, but given the default settings, I doubt that the team will consider it as one.

+3

, , , - , ... StringFormat TextBox:

Text="{Binding Path=YourDecimalOrDouble, StringFormat=\{0:#.#####\}, UpdateSourceTrigger=PropertyChanged}

, ... , .

, , !

0

All Articles