WPF 界面实现多语言支持 中英文切换 动态加载资源字典
1、使用资源字典,首先新建两个字典文件en-us.xaml、zh-cn.xaml。定义中英文的字符串在这里面【注意:添加xmlns:s="clr-namespace:System;assembly=mscorlib】
zh-cn.xam如下:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfApplication">
<s:String x:Key="buttonNewTaskWindow">新建任务</s:String>
<s:String x:Key="buttonProperty">任务属性</s:String>
< /ResourceDictionary>
en-us.xaml如下:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfApplication">
<s:String x:Key="buttonNewTaskWindow">New Task</s:String>
<s:String x:Key="buttonProperty">Task Property</s:String> </ResourceDictionary>
<Application x:Class="WpfApplication.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="Resources\en-us.xaml"/>
<ResourceDictionary Source="Resources\zh-cn.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </Application.Resources>
< /Application>
3、在界面设计器中需要显示的位置添加动态资源
<Button x:Name="buttonNewTaskWindow" Content="{DynamicResource buttonNewTaskWindow}"/>
<Button x:Name="buttonProperty" Content="{DynamicResource buttonProperty}"/>
List<ResourceDictionary> dictionaryList = new List<ResourceDictionary>();
foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
{
dictionaryList.Add(dictionary);
}
string requestedCulture = @"Resources\en-us.xaml";
ResourceDictionary resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture));
Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary);
Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
WPF 界面实现多语言支持 中英文切换 动态加载资源字典的更多相关文章
- vue 实现tab切换动态加载不同的组件
vue 实现tab切换动态加载不同的组件 使用vue中的is特性来加载不同的组件.具体看如下代码:这个功能对于vue比较复杂的页面可以使用上,可以把一个页面的功能拆分出来,使代码更简单.使用方式具体看 ...
- Ext选项卡tabpanel切换动态加载数据
鸣人不说暗话,来张图: 代码开始:(使用Ext,ajax加载数据,如果你们有好的方法也可以多多交流)var tabxsk = new Object(); //初始化 tabxsk.init = fun ...
- [WPF学习笔记]动态加载XAML
好久没写Blogs了,现在在看[WPF编程宝典],决定开始重新写博客,和大家一起分享技术. 在编程时我们常希望界面是动态的,可以随时变换而不需要重新编译自己的代码. 以下是动态加载XAML的一个事例代 ...
- 界面动态加载时报NullPointException
今天在做环境监测的模拟软件时,登陆页面报NullPointException 一般像我们初始化Button时,是Button btn=(Button)findViewById(R.id.button1 ...
- WPF动态加载3D 放大-旋转-平移
原文:WPF动态加载3D 放大-旋转-平移 WavefrontObjLoader.cs 第二步:ModelVisual3DWithName.cs public class ModelVisual3DW ...
- 通过Activity动态加载Fragment创建主界面构架
在做项目中,需要建立一个主界面框架,尝试过使用ViewPager ,后来又换成了使用Activity动态加载Fragment实现选项卡的效果.总结一下方便以后回顾. 先给出总体效果: 要实现上述效果, ...
- 180729-Quick-Task 动态脚本支持框架之任务动态加载
Quick-Task 动态脚本支持框架之任务动态加载 前面几篇博文分别介绍了整个项目的基本架构,使用说明,以及整体框架的设计与实现初稿,接下来则进入更细节的实现篇,将整个工程中核心实现捞出来,从为什么 ...
- mvvm模式下在WPF项目中动态加载项目的程序集和类
在mvvm模式的wpf项目中有个需求需要去加载解决方案的程序集,并且根据程序集去动态加载当前程序集的类,做成下拉框形式. 效果: //全局定义 private ComboBox abList= nul ...
- WPF 动态加载主题由zip
经典主题的方式 主题战略 加载速度 本机支持 (不需要额外的代码) 支持代码为主题 (捆绑代码 & 资源成单独的文件) 支持资源层次结构中导航 动态加载 动态卸载 轻松地编辑和编译 (不需要安 ...
随机推荐
- 反向代理:是指以代理server来接收Internet上的请求,然后将请求转发到内部网络的server上,并将结果返回给Internet上连接的client,此时的代理server对外就表现为反向代理server。
Nginx安装好之后.開始使用它来简单实现反向代理与负载均衡的功能.在这之前.首先得脑补一下什么是反向代理和负载均衡. 反向代理:是指以代理server来接收Internet上的请求,然后将 ...
- Write Code As If You Had to Support It for the Rest of Your Life
Write Code As If You Had to Support It for the Rest of Your Life Yuriy Zubarev YOU COULD ASK 97 PEOP ...
- valgrind,arm-linux交叉编译
1. 下载及解压valgrind-3.9.0 2.CC=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux ...
- RocketMQ 安装详细说明
原文:RocketMQ 安装详细说明 目录 本文导读 环境说明 RocketMQ 下载 从 Apache 下载 从 GitHub 下载 RocketMQ 安装 文件上传 项目解压 编译部署 Rocke ...
- css3 实现水晶按钮
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ee432e), color-sto ...
- 关于如何在Sublime下安装插件
安装插件的两种方式 通过Package Control安装 不能安装 手工安装 安装插件的两种方式 在sublime下安装插件有两种方式,一种是通过package control来进行安装,另一种呢就 ...
- 基于GTID多源复制扩展
对一个运行很久的库做备份恢复建同步 不能使用xtrabackup 使用mysqldump导数据: mysqldump -S /data/mysql/3307/tmp/3307.sock --sin ...
- [Ramda] Change Object Properties with Ramda Lenses
In this lesson we'll learn the basics of using lenses in Ramda and see how they enable you to focus ...
- [React] displayName for stateless component
We can use 'displayName' on component to change its component tag in dev tool: import React from 're ...
- css中背景 字体 文体属性练习
@charset "utf-8"; body{ background-color:#332244;/*//背景颜色*/ background-image:("../kk. ...