【AvaloniaUI语言国际化I18n】图文结合教学,保姆级教学,语言国际化就是这么简单(.NetC#)
- 电脑硬件
- 2025-08-23 07:36:01

完整项目地址
github : github /Crazy-GrowUp/AvaloniaI18nTest/tree/master gitee : gitee /jack_of_disco/avalonia-i18n-test
0.项目新建 Properties 文件夹对应的项目配置文件里面就会增加 <Folder Include="Properties\" />
1.项目添加新建项目在 Properties 里面添加资源文件,命名为 Resource.resx
2.将自定义工具设置为 PublicResXFileCodeGenerator(重要)右键 Resource.resx 文件,打开属性,修改属性中自定义工具为 PublicResXFileCodeGenerator
3.添加文本资源4.安装扩展 ResXManager(推荐)
安装完成后,可能需要重启VS
5.添加多国语言方式一:右键 Resource.resx 使用 ResXManager 打开
Properties 文件夹下面就多了一个 Resource.en.resx
方式二:手动添加多国语言文件
比如我们要添加中文,那么就新建 Resource.zh.resx 资源文件
然后将对应的翻译填写到资源文件中
6.在 .axaml 文件中使用 在 MainWindow.axaml 中加上 xmlns:prop="using:AvaloniaI18nTest.Properties"通过 {x:Static prop:Resource.Name} 进行使用 7.在代码中使用在 MainWindowViewModel 中 使用 using AvaloniaI18nTest.Properties; 或者 using prop = AvaloniaI18nTest.Properties;
取出其中的值
public string ResxName { get; } = Resource.Name; public string ResxName2 { get; } = prop.Resource.Name;在 axaml 中显示
8.切换语言切换需要需要在 App.axaml.cs 中的 Initialize() 方法中进行设置
// 不写或者为空就是默认系统语言 // Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(""); // 修改语言 // Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh"); Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");【AvaloniaUI语言国际化I18n】图文结合教学,保姆级教学,语言国际化就是这么简单(.NetC#)由讯客互联电脑硬件栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“【AvaloniaUI语言国际化I18n】图文结合教学,保姆级教学,语言国际化就是这么简单(.NetC#)”