WPF页面 全球化和本地化
传统的 新建.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页面 全球化和本地化的更多相关文章
- WPF全球化与本地化
当一个App需要推出多语言版本时,就需要使用到[全球化与本地化]服务. 原理及过程 资源文件中包含了所有的控件信息,通过导出这些控件信息,修改其对应的相关属性(比如TextBlock的Text属性)的 ...
- Asp.Net Core 混合全球化与本地化支持
前言 最近的新型冠状病毒流行让很多人主动在家隔离,希望疫情能快点消退.武汉加油,中国必胜! Asp.Net Core 提供了内置的网站国际化(全球化与本地化)支持,微软还内置了基于 resx 资源字符 ...
- ASP.NET Core搭建多层网站架构【13-扩展之支持全球化和本地化多语言】
2020/02/03, ASP.NET Core 3.1, VS2019, ResXManager 摘要:基于ASP.NET Core 3.1 WebApi搭建后端多层网站架构[13-扩展之支持全球化 ...
- ASP.NET Core 中文文档 第三章 原理(6)全球化与本地化
原文:Globalization and localization 作者:Rick Anderson.Damien Bowden.Bart Calixto.Nadeem Afana 翻译:谢炀(Kil ...
- WPF页面跳转
WPF页面跳转有两种:一种是windows,另外一种是page 1:windows页面跳转windows 页面跳转相信学过winform编程的哥们都知道,先实例化该窗体然后show一下就可以了.eg ...
- WPF页面切换及弹窗
WPF页面切换及弹窗 结构如图: 效果如图: 代码如下: xaml <Window x:Class="PageChange.MainWindow" xmlns="h ...
- WPF 页面切换效果
原文:WPF 页面切换效果 最近做一个有页面切换的吧.. 我觉得这个功能是比较基础的吧.. 在网上百度了一下.. 用NavigationWindow的比较好.. 因为Demo中是带了淡入淡出的页面效果 ...
- WPF页面刷新
WPF页面刷新: 在WPF项目中,类的属性变了,但界面值没有变,且我们也没有对类的属性做PropertyChanged的set处理. 如何实现呢? 首先我们需要实现一个INotifyPropertyC ...
- WPF全球化与本地化 (二)
Visual Baml Visual Locbaml is a free and open-source software to simplify the task of WPF applicatio ...
随机推荐
- Windows下安装Tomcat服务
startup.bat中添加以下内容 setlocal SET JAVA_HOME=D:\Program Files\Java\jdk1.8.0_05 SET CATALINA_HOME=D:\Pro ...
- 新浪微博客户端(36)-自定义带placeholder的TextView
iOS 上自带的UITextView竟然不能设置placeholder,但是UITextView却可以,我也真是醉了.没办法了,自己写一个 DJTextView.h #import <UIKit ...
- Eclipse里项目名有红叉,但是底下的每一个文件都没有红叉
如果是因为java compiler level does not match the version of the installed java, 那么我们打开项目的properties,有一个选项 ...
- MySql循环插入数据(定义了存储过程)
MySQL一窍不通啊,今天工作上需要用到,请教了别人,做以备忘 DROP PROCEDURE test_insert ; DELIMITER ;; CREATE PROCEDURE test_inse ...
- 配置lamp中的apache
root@komiles-VirtualBox:/etc/apache2/sites-available# service apache2 restart * Restarting web serve ...
- 论Linux运维的一些基础安全知识和简单办法
不知不觉本人来北京也已经第三个年头了,从一个Linux小小鸟,开始,2012年我参加了第一份工作,其实现在想想其实我是幸运的,本来求学的时候,就没好好的学Linux,我认为有Cisco知识从上wind ...
- c++异常总结
堆栈辗转开解(stack-unwinding):如果一个函数中出现异常,在当前函数内即通过 try..catch 捕捉(且捕捉到)的话,可以继续往下执行:如果不捕捉(或未捕捉到)就会抛出(与通过 th ...
- 解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX
从网上抓了一些字节流,想打印出来结果发生了一下错误: UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position ...
- List<List<double>> lsls = null; 根据double值来重新排序lsls...
"确定:Node-data = (7,2).具体是:根据x维上的值将数据排序, 6个数据的中值(所谓中值,即中间大小的值)为7, 所以Node-data域位数据点(,).这样, 该节点的分割 ...
- debian8 配置使用 nfs
操作过的步骤: 1.dpkg-reconfigre rpcbind. 2.在终端上退出要挂载的目录. 错误:mount -t nfs 172.16.0.121:/home/junda /mnt,出现以 ...