Thomas Bratt
Thomas Bratt

Reputation: 51774

How to localise WPF application so that right to left languages are displayed correctly?

What steps are required to localise a WPF application so that right to left languages are displayed correctly?

Upvotes: 2

Views: 2005

Answers (2)

Mozart
Mozart

Reputation: 2302

For my use case adding below code in MainWindow.cs was enough:

    public MainWindow()
    {
        InitializeComponent();
        // Here
        this.FlowDirection =
            CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft ?
                FlowDirection.RightToLeft :
                FlowDirection.LeftToRight;
    }

Upvotes: 0

NVM
NVM

Reputation: 5552

I realize its an old question but I am stuck with this as well so am adding what I've done (which works partially) in the hope that someone will add more to it

In your app.cs you can do something like this

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        FrameworkElement.LanguageProperty.OverrideMetadata(
          typeof(FrameworkElement),
          new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

        FrameworkElement.FlowDirectionProperty.OverrideMetadata(
        typeof(FrameworkElement),
        new FrameworkPropertyMetadata(CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft
                                      ? FlowDirection.RightToLeft : FlowDirection.LeftToRight));

    }

Now this flips everything all right but it also happens to flip all images which is not what you really want.

Upvotes: 2

Related Questions