JSchwartz
JSchwartz

Reputation: 2724

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);

Upvotes: 1

Views: 269

Answers (1)

Avestura
Avestura

Reputation: 1557

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 = ...
});

Upvotes: 2

Related Questions