zoukankan      html  css  js  c++  java
  • WPF程序国际化

    1.创建相应的xaml文件

    <ResourceDictionary
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sp="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
        xmlns:sys="clr-namespace:System;assembly=mscorlib">
    
    
        <sp:ImageSource x:Key="Logo">
            logo url
        </sp:ImageSource>
    
        <sys:String x:Key="Msg">
           string
        </sys:String>
    
    </ResourceDictionary>

    2.配置App.xaml

    <Application.Resources>
    <ResourceDictionary>
    <!-- 这个节点就是配置默认语言的 -->
    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Languagesen_US.xaml" />
    </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    </Application.Resources>

    3.程序中如果要修改,则可以使用如下代码

                    ResourceDictionary langRd = null;
                    try
                    {
                        //base on language config file
                        langRd = Application.LoadComponent(new Uri(@"Languages" + languageName + ".xaml", UriKind.Relative)) as ResourceDictionary;
                    }
                    catch (Exception e2)
                    {
                        MessageBox.Show(e2.Message);
                    }
    
                    if (langRd != null)
                    {
                        //clear base style
                        //if (this.Resources.MergedDictionaries.Count > 0)
                        //{
                        //    this.Resources.MergedDictionaries.Clear();
                        //}
                        this.Resources.MergedDictionaries.Add(langRd);
                    }

     4.如果要单独取得某个配置项目,则可以在程序中使用如下代码:

    using System.Windows
    (string)TryFindResource("Msg");
  • 相关阅读:
    技术收集
    Entity Framework的扩展库
    暂时收集
    php 处理高并发的思路
    nginx缓存优先级(缓存问题者必看)
    mysql5.5主从配置
    php源码编译常见错误解决方案
    今天开始要改变模式了
    nrpe 在ubuntu上安装遇到的问题
    zendstudio 10下载汉化
  • 原文地址:https://www.cnblogs.com/amwuau/p/7513997.html
Copyright © 2011-2022 走看看