数字向后显示? [英] Numbers displaying backwards?

查看:86
本文介绍了数字向后显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我阅读用户的投诉时,我不相信它.在绑定的WPF文本框中输入.123时显示为.321!作为WPF错误?

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?

当文本框绑定到Entity Framework double字段且UpdateSourceTrigger绑定模式设置为PropertyChanged时,会发生此问题.在小数点后键入每个数字时,光标将移回到小数点之后,从而导致数字倒退.当我将UpdateSourceTrigger重新设置为LostFocus的默认值时,问题(可以理解)消失了.

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.

那么,这是一个错误吗?有没有一种解决方法,当绑定到双精度字段时,可以允许UpdateSourceTrigger进行PropertyChanged?

推荐答案

将TextBox设置为LostFocus而不是PropertyChanged是有原因的.将其绑定到EF double时,验证可能会导致重置该值,从而又会重置光标位置.

There is a reason that TextBox is set to LostFocus and not PropertyChanged. 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.

使用UpdateSourceTrigger.PropertyChanged使TextBox正确运行需要大量的自定义逻辑,因为您需要在绑定更新之前跟踪事件中的光标位置,然后再进行还原.

Making a TextBox behave correctly with UpdateSourceTrigger.PropertyChanged requires a fair amount of custom logic, as you need to track cursor positions in events prior to the binding update, and restore afterwards.

不过,我怀疑这会被视为错误,因为WPF将TextBox设置为UpdateSourceTrigger.LostFocus.如果默认设置不同,则我同意这将是一个错误-但鉴于默认设置,我怀疑团队会将其视为一个.

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.

这篇关于数字向后显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆