[英]decimal removed after validation @ WPF Textbox
I create a Textbox in Code behinde and bind it to a double Property. 我在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);
When i enter a value like 45,45 (comma) it is parsed to 4545. 当我输入一个像45,45(逗号)的值时,它被解析为4545。
If i enter 45.45 (point) it is parsed correct with 45,45. 如果我输入45.45(点),则用45,45解析它是正确的。
I use German language Settings and my decimal Sperator is , 我使用德语设置,我的小数Sperator是,
What am i doing wrong? 我究竟做错了什么?
Try setting binding. 尝试设置绑定。 ConverterCulture to your target culture. ConverterCulture到您的目标文化。
For example 例如
binding.ConverterCulture = CultureInfo.CurrentCulture;
A clear, not culture specific solution is to add this to your App.xaml.cs and normally WPF will always use the correct culture - regional settings: 一个明确的,而不是特定于文化的解决方案是将其添加到App.xaml.cs中,通常WPF将始终使用正确的文化 - 区域设置:
static App()
{
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
}
Did you tried 你试过吗?
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.