MahApps / MahApps.Metro

A framework that allows developers to cobble together a better UI for their own WPF applications with minimal effort.
https://mahapps.com
MIT License
9.27k stars 2.45k forks source link

Can't localize globalization #4155

Open raozhihao opened 3 years ago

raozhihao commented 3 years ago

I want to set Application.Current.Dispatcher.Thread.CurrentUICulture

To localize, but not ,if I reference

When, the right-click menu of TextBox on my form is Chinese language, and set Application.Current.Dispatcher.Thread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");

At this time, the right-click menu of TextBox is not changed to English language

If I don't reference it, I can change it

raozhihao commented 3 years ago

When i reference on App.xaml,I set Application.Current.Dispatcher.Thread.CurrentUICulture, It doesn't work When i don't reference ,It can do it

punker76 commented 3 years ago

@raozhihao Please provide a sample app. Thx

raozhihao commented 3 years ago

This is code

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>

                <!--if not reference ,right click can change language-->

                <!--<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />-->
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <!-- Theme setting -->
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />

            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
<mah:MetroWindow x:Class="MahLang.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <StackPanel>
        <TextBox Text="Pelase mouse right clik ,look this language" />
        <Button Content="Change Language"
                Click="Button_Click" />
        <TextBlock Text="zh-CN"
                   x:Name="langTxt" />
    </StackPanel>
</mah:MetroWindow>
        bool useZhCN = false;
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string cultureStr = "zh-CN";
            if (!useZhCN)
                cultureStr = "en-US";

            this.langTxt.Text = cultureStr;
            Application.Current.Dispatcher.Thread.CurrentUICulture = new CultureInfo(cultureStr);
        }
raozhihao commented 3 years ago

https://github.com/raozhihao/LangTest/tree/master/MahLang

This test sln