[英]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是,
我究竟做錯了什么?
一個明確的,而不是特定於文化的解決方案是將其添加到App.xaml.cs中,通常WPF將始終使用正確的文化 - 區域設置:
static App()
{
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
}
你試過嗎?
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.