WPF XAML StringFormat DateTime: Output in wrong culture?

前端 未结 6 1474
南旧
南旧 2021-02-03 16:49

I\'m having some trouble with the output of a DateTime value. My computer\'s current culture is set to de-AT (Austria).

The following code

string s1 = Da         


        
6条回答
  •  盖世英雄少女心
    2021-02-03 17:34

    To apply the solution mentioned at http://tinyurl.com/b2jegna do the following:

    (1) Add a Startup event handler to the Application class in app.xaml:

    
    

    (2) Add the handler function:

    private void ApplicationStartup(object sender, StartupEventArgs e)
    {
        FrameworkElement.LanguageProperty.OverrideMetadata(
            typeof(FrameworkElement),
            new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
    }
    

    WPF strings should then be formatted correctly according to culture.

提交回复
热议问题