绑定到文本框 [英] Binding Double to TextBox

查看:166
本文介绍了绑定到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常使用TextBox绑定到整数没有太多的问题。



但是,如果我尝试将一个TextBox绑定到一个Double它不起作用。 p>

当我键入5,85(作为我的文化decimalSeperator),我将585.0传递给双重值。



是否被转换,我可以使用什么解决方案来解决这个问题? ValueConverter将是最好的解决方案?

解决方案

您可以尝试将其添加到应用程序的构造函数中:

  FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

但是,请注意,如果您自定义小数分隔符,这将不起作用。 (使用自定义小数分隔符的WPF双值数据绑定


I have often used TextBox to bind to Integers without much problem.

However if I try to bind a TextBox to a Double it doesn't work.

When I type 5,85 ( , being my cultures decimalSeperator) I pass 585.0 to the double value.

How is it being converted and what solution could I use to fix this? Would a ValueConverter be the best solution?

解决方案

You could try adding this to your application's constructor:

FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
             new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

However, please note that this will not work if you customize the decimal separator. (WPF double valued data binding with custom decimal separator)

这篇关于绑定到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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