传统的 新建.resx类型的文件中,然后利用ResourceManager来得到相应资源并根据当地的CultureInfo来给界面文本赋值。

WPF

新建一个文件夹 Language

新建2个资源字典。

DefaultLanguage.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<sys:String x:Key="OK">
OK
</sys:String> <sys:String x:Key="Cancel">
Cancel
</sys:String>
</ResourceDictionary>

zh-CN.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"> <sys:String x:Key="OK">
确定
</sys:String> <sys:String x:Key="Cancel">
取消
</sys:String> </ResourceDictionary>

App.xaml 引入路径

<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"> <Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Language\DefaultLanguage.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </Application.Resources>
</Application>

App.cs代码:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Globalization; namespace WpfApplication1
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
LoadLanguage();
} private void LoadLanguage()
{
CultureInfo currentCultureInfo = CultureInfo.CurrentCulture;
ResourceDictionary langRd = null; try
{
langRd = Application.LoadComponent(new Uri(string.Format("{0}{1}.xaml", "Language\\", currentCultureInfo.Name), UriKind.Relative)) as ResourceDictionary;
}
catch
{
} if (langRd != null)
{
if (this.Resources.MergedDictionaries.Count > )
{
this.Resources.MergedDictionaries.Clear();
}
this.Resources.MergedDictionaries.Add(langRd);
} }
}
}

页面使用:

            <Button Content="{DynamicResource OK}"/>
<Button Content="{DynamicResource Cancel}"/>

WPF页面 全球化和本地化的更多相关文章

  1. WPF全球化与本地化

    当一个App需要推出多语言版本时,就需要使用到[全球化与本地化]服务. 原理及过程 资源文件中包含了所有的控件信息,通过导出这些控件信息,修改其对应的相关属性(比如TextBlock的Text属性)的 ...

  2. Asp.Net Core 混合全球化与本地化支持

    前言 最近的新型冠状病毒流行让很多人主动在家隔离,希望疫情能快点消退.武汉加油,中国必胜! Asp.Net Core 提供了内置的网站国际化(全球化与本地化)支持,微软还内置了基于 resx 资源字符 ...

  3. ASP.NET Core搭建多层网站架构【13-扩展之支持全球化和本地化多语言】

    2020/02/03, ASP.NET Core 3.1, VS2019, ResXManager 摘要:基于ASP.NET Core 3.1 WebApi搭建后端多层网站架构[13-扩展之支持全球化 ...

  4. ASP.NET Core 中文文档 第三章 原理(6)全球化与本地化

    原文:Globalization and localization 作者:Rick Anderson.Damien Bowden.Bart Calixto.Nadeem Afana 翻译:谢炀(Kil ...

  5. WPF页面跳转

    WPF页面跳转有两种:一种是windows,另外一种是page  1:windows页面跳转windows 页面跳转相信学过winform编程的哥们都知道,先实例化该窗体然后show一下就可以了.eg ...

  6. WPF页面切换及弹窗

    WPF页面切换及弹窗 结构如图: 效果如图: 代码如下: xaml <Window x:Class="PageChange.MainWindow" xmlns="h ...

  7. WPF 页面切换效果

    原文:WPF 页面切换效果 最近做一个有页面切换的吧.. 我觉得这个功能是比较基础的吧.. 在网上百度了一下.. 用NavigationWindow的比较好.. 因为Demo中是带了淡入淡出的页面效果 ...

  8. WPF页面刷新

    WPF页面刷新: 在WPF项目中,类的属性变了,但界面值没有变,且我们也没有对类的属性做PropertyChanged的set处理. 如何实现呢? 首先我们需要实现一个INotifyPropertyC ...

  9. WPF全球化与本地化 (二)

    Visual Baml Visual Locbaml is a free and open-source software to simplify the task of WPF applicatio ...

随机推荐

  1. Linq 中的 left join

    Linq 中的 left join 表A User: 表B UserType: Linq: from t in UserType join u in User on t.typeId equal u. ...

  2. java批量生成excel代码分享

    package com.test.util; /** * @author ocq * */ import java.io.FileOutputStream; import java.io.IOExce ...

  3. XPath使用小结

    参考资料: http://www.w3school.com.cn/xpath/xpath_nodes.asp

  4. linux shell 报错 Syntax error: Bad for loop variable

    在linux下写了一个简单的shell,循环10次. test.sh #!/bin/bash ## ##循环10次 ## ; i<; i++)); do echo Good Morning ,t ...

  5. linux下如何安装charles

    charles是很好的抓包工具. 如何安装呢? 可以去官网下载:http://www.charlesproxy.com/download/ 如果是Debian系列的,可以直接用apt-get 安装 h ...

  6. height:100%和height:auto的区别

    一直不明白height:100%和height:auto的区别,最近在制作前端页面时都用了height:100%;overflow:hidden; ,可是有些浏览器出现莫名的奇妙的问题,但换成heig ...

  7. Ruby基本语法规则

    1.Ruby常用数据类型 Numbers, Strings, Booleans my_num = 25 my_boollean = true (or false) my_string = " ...

  8. webApp前端开发技巧总结

    自Iphone和Android这两个牛逼的手机操作系统发布以来,在互联网界从此就多了一个新的名词-WebApp(意为基于WEB形式的应用程序,运行在高端的移动终端设备.我相信各位童鞋应该和我一个样子, ...

  9. MySQL中快速复制数据表方法汇总

    本文将着重介绍两个MySQL命令的组合,它将以原有数据表为基础,创建相同结构和数据的新数据表. 这可以帮助你在开发过程中快速的复制表格作为测试数据,而不必冒险直接操作正在运行 的数据表. 示例如下: ...

  10. iOS开发——UI进阶篇(十三)UITabBarController简单使用,qq主流框架

    一.UITabBarController简单使用 // 程序加载完毕 - (BOOL)application:(UIApplication *)application didFinishLaunchi ...