验证@ 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;更多推荐
发布评论