验证@ WPF文本框后删除了小数(decimal removed after validation @ WPF Textbox)

编程入门 行业动态 更新时间:2024-10-25 04:17:26
验证@ WPF文本框后删除了小数(decimal removed after validation @ WPF Textbox)

我在Code behinde中创建了一个Textbox并将其绑定到double属性。

TextBox t = new TextBox(); t.Width = 80; t.DataContext = s; Binding binding = new Binding(); binding.Mode = BindingMode.TwoWay; binding.Path = new PropertyPath("Value"); BindingOperations.SetBinding(t, TextBox.TextProperty, binding);

当我输入一个像45,45(逗号)的值时,它被解析为4545。

如果我输入45.45(点),则用45,45解析它是正确的。

我使用德语设置,我的小数Sperator是,

我究竟做错了什么?

I create a Textbox in Code behinde and bind it to a double Property.

TextBox t = new TextBox(); t.Width = 80; t.DataContext = s; Binding binding = new Binding(); binding.Mode = BindingMode.TwoWay; binding.Path = new PropertyPath("Value"); BindingOperations.SetBinding(t, TextBox.TextProperty, binding);

When i enter a value like 45,45 (comma) it is parsed to 4545.

If i enter 45.45 (point) it is parsed correct with 45,45.

I use German language Settings and my decimal Sperator is ,

What am i doing wrong?

最满意答案

尝试设置绑定。 ConverterCulture到您的目标文化。

例如

binding.ConverterCulture = CultureInfo.CurrentCulture;

Try setting binding.ConverterCulture to your target culture.

For example

binding.ConverterCulture = CultureInfo.CurrentCulture;

更多推荐

本文发布于:2023-07-30 22:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340318.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小数   文本框   WPF   decimal   Textbox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!