Search code examples
wpfxamldata-bindingivalueconverter

Binding Double to TextBox


I have often used TextBox to bind to Integers without much problem.

However if I try to bind a TextBox to a Double it doesn't work.

When I type 5,85 ( , being my cultures decimalSeperator) I pass 585.0 to the double value.

How is it being converted and what solution could I use to fix this? Would a ValueConverter be the best solution?


Solution

  • You could try adding this to your application's constructor:

    FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
                 new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
    

    However, please note that this will not work if you customize the decimal separator. (WPF double valued data binding with custom decimal separator)