WPF XAML Bindings and CurrentCulture Display

前端 未结 2 1647
一整个雨季
一整个雨季 2020-11-30 11:59

I\'m seeing some invalid behavior from XAML documents when the CurrentCulture is changed. When I have some elements like this in a Window:



        
2条回答
  •  北海茫月
    2020-11-30 12:29

    It turns out that WPF does not respect the CurrentCulture by default in bindings, and instead defaults to xml:Lang setting defined in the XAML document or en-US if not provided. This is rather lame behavior - not sure why you would NOT have automatic culture formatting applied as every other UI technology, but...

    Luckily there's an easy workaround that can be applied in the document's constructor or a Window/UserControl base class:

            // MAKE SURE you set the language of the page explicitly or else
            // all number and date formatting occurs using 
            this.Language = XmlLanguage.GetLanguage(
                            CultureInfo.CurrentCulture.IetfLanguageTag);
    

    There's more information available in this blog post:

    http://www.west-wind.com/weblog/posts/796725.aspx

提交回复
热议问题