WPF TextBox binding to decimal respecting culture

青春壹個敷衍的年華 提交于 2019-12-21 03:42:33

问题


I've bound a TextBox to a Decimal. My problem ist, the Binding is using american numerical standards, using a dot for decimals separation ("1.5")

My system is german and configured to use a comma as decimals separation ("1,5").

I need the TextBox binding to show and use a comma instead of a dot to separate decimals.

How do I get the binding to respect the currently set localization/culture settings for numerical input?


回答1:


Read this article. You should set default language for all framework elements:

public partial class App : Application
{
    static App()
    {
        FrameworkElement.LanguageProperty.OverrideMetadata(
            typeof(FrameworkElement),
            new FrameworkPropertyMetadata(
                XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
    }
}


来源:https://stackoverflow.com/questions/3878877/wpf-textbox-binding-to-decimal-respecting-culture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!