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 ...
随机推荐
- 让Xcode的控制台支持LLDB类型的打印
这个技巧个人认为非常有用 当Xcode在断点调试的时候,在控制台中输入 po self.view.frame 类似这样的命令会挂掉,不信可以亲自去试试(Xcode7 以后支持LLDB类型的打印) 那么 ...
- jquery access方法 有什么用
Jquery设置对象属性的有几种方法1.获取属性attr(name) 2.设置属性attr(name,value)3.批量设置属性attr(properties)4.为所有匹配的元素设置一个计算的属性 ...
- 【转】跟我学Kafka之NIO通信机制
from:云栖社区 玛德,今天又被人打脸了,小看人,艹,确实,相对比起来,在某些方面差一点,,,,该好好捋捋了,强化下短板,规划下日程,,,引以为耻,铭记于心. 跟我学Kafka之NIO通信机制 ...
- CSS 有关margin padding
- VS2008上借助VA来提示QT API
1.打开VS,工具-->选项-->项目和解决方案-->VC++目录,在右侧下拉框中选择-->包含文件,添加QT的include目录 2. 打开VA配置页,Projects--& ...
- 设置p标签自动换行
<body> <p style="width:20px;height:100px;background-color:#069; word-wrap: break-w ...
- linux之vim编辑神器
设置编辑器:export EDITOR=vim 1.ctrl+x ctrl+e 创建vim临时文件 2.ctrl+[ 退回到命令模式 3.命令模式下ZZ,保存退出 4.大写I行首插入,大写A行尾插入 ...
- MFC关闭子窗口 如何把父窗口也一起关闭
在子窗口OnClose() 消息里添加: GetParent()->DestroyWindow();//子窗口关闭 父窗口也同样关闭
- Javascript高级程序设计——面向对象之理解对象
在面向对象语言中都有类的概念,通过类来创建具有属性和方法的对象.而ECMAScript中没有类的概念,ECMAScript中定义了对象:无需属性的集合,其属性值可以包含基本值.对象.或者函数. 在Ja ...
- 解决Button设置disabled后无法执行后台代码问题
一.开始调式下面的程序,发现Button在js中设置disabled后无法执行后台代码(btnsave_Click)问题 <asp:Button ID="btnsave" r ...