简体   繁体   中英

How to set the DateFormat (Language) in a textbox?

I have a WPF application where I am dynamic creating the XAML which includes a textbox to display the current DATE and I want to show it in FRENCH (because it includes the day of the week).

In the XAML itself this is easy:

<TextBox Name="OrderDateText"
    Text="{Binding Path=OrderDate, StringFormat=dddd: dd-MM-yyyy}"
    xml:lang="fr-CA"

However when done in CODE I cannot seem to figure out how to set the language:

TextBox txtboxOrderdDate = new TextBox();
txtboxOrderdDate.Language = ???????????????????
{
   StringFormat = "dddd: dd-MM-yyyy"
};
txtboxOrderdDate.SetBinding(TextBox.TextProperty, binding);

Use XMLLanguage from System.Windows.Markup namespace:

txtboxOrderdDate.Language = XmlLanguage.GetLanguage("fr-CA");

Note that based on your Xaml, you should set StringFormat in your Binding , not in Language .

txtboxOrderdDate.SetBinding(TextBox.TextProperty, new Binding()
{
    StringFormat = "some format here",
    OtherProps = ...
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM