Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

c# - WPF: Localization using x:Uid and resx

I'm trying to switch application language at application runtime by using x:Uid and resx.
I have already set up the cultureinfo to the language I want in App.cs.

CultureInfo culture = new CultureInfo("zh-CN");

CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;

Thread.CurrentThread.CurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;

and I have some string under /Language/zh-CN/Resources.resx file.

Control_ConnectButton.Content 连接
Control_TestButton.Content 测试

Button xaml

<Button x:Name="ConnectButton" x:Uid="Control_ConnectButton" VerticalAlignment="Center"
        Click="ConnectButton_Click" Margin="28,0,0,0" MinWidth="70" />
<Button x:Name="TestButton" x:Uid="Control_TestButton" VerticalAlignment="Center"
        Click="TestButton_Click" Margin="28,0,0,0" MinWidth="70" />

However when I start the application, the text on the button is empty.
enter image description here

What did I do wrong?

I'm using .NET Framework 4.6.1

question from:https://stackoverflow.com/questions/65881929/wpf-localization-using-xuid-and-resx

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...