2

I have a TextBlock bound to a string. I want the string to be displayed in current UI culture of the application. I want to do this in XAML. The text block is simple like below.

<TextBlock Text="{Binding Path=Text}"/>

Prince Ashitaka
  • 8,623
  • 12
  • 48
  • 71

1 Answers1

2

You need to set the FrameworkElement.Language property. The easiest way to do that for the whole application is to override the property metadata in the App class static constructor:

public partial class App : Application
{
    static App()
    {
        FrameworkElement.LanguageProperty.OverrideMetadata(
            typeof(FrameworkElement),
            new FrameworkPropertyMetadata(
                XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
    }
}

If you only want to set the culture for a specific control, you can bind its Language property to a property of your datacontext:

<TextBlock Text="{Binding Something}" Language="{Binding TheLanguage}" />
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
  • Thanks Thomas, but, I need to do this for my custom control library. I happened to see the CultureConverter in binding. But, I dono't know how to use that to set the current culture. It is not a dependency property. :( – Prince Ashitaka Sep 17 '10 at 12:28