WP8 DLL Class library (SDK) for multilingual multi-theme

Source: Internet
Author: User

Recently in the implementation of an SDK project, because to achieve multi-language switching, single-class library multi-language implementation is not many, so the collation is as follows.

1. Add Appresource.resx (English) and Appresource-zh-cn.resx

Suppose our default language is English, add these two files. Add the Usercenter_title field to each of the two resource files and assign it a value. Note The access modifier is set to public.

If you are implementing multiple themes, you can add resources such as pictures.

2. Add Localizedstrings Class

Inherit INotifyPropertyChanged and implement, the final code may be as follows

12345678910111213141516171819202122232425262728293031323334 public class AdeasygoLocalizedStrings : INotifyPropertyChanged    {        private static AppResource _localizedResources = new AppResource();        public AppResource AdeasygoLocalizedResource        {            get            {                return _localizedResources;            }            set            {                 _localizedResources = value;                NotifyPropertyChanged("AdeasygoLocalizedResource");            }        }         public event PropertyChangedEventHandler PropertyChanged;        public void NotifyPropertyChanged(string propertyName)        {            if (this.PropertyChanged != null)            {                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));            }        }    }
3.Modify AppResource.Designer.cs

This step is important to add the set method of the ResourceManager property to support dynamic language switching:

1234567891011121314 /// <summary>        ///   返回此类使用的缓存的 ResourceManager 实例。        /// </summary>        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]        public static global::System.Resources.ResourceManager ResourceManager {            get {                if (object.ReferenceEquals(resourceMan, null)) {                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Adeasygo.Community.Sdk.Resources.AppResource", typeof(AppResource).Assembly);                    resourceMan = temp;                }                return resourceMan;            }            set { resourceMan = value; }        }
4. Control Language (theme) toggle
1234567891011121314 public static void Init(string lang = "en")        {            ResourceManager resManager;            switch (lang)            {                case "zh":                    resManager = new ResourceManager("Sdk.Resources.AppResource-zh-CN", Assembly.Load("Sdk"));                    break;                default:                    resManager = new ResourceManager("Sdk.Resources.AppResource", Assembly.Load("Sdk"));                    break;            }            AppResource.ResourceManager = resManager;        }

In this way, the dynamic language switching, image resources and so on in the class library can also be defined in the ResX, depending on the language change or multi-topic switching.

This article fixed link: http://www.liubaicai.net/index.php/archives/425

Welcome to visit: http://www.liubaicai.net/Find more

WP8 DLL Class library (SDK) for multilingual multi-theme

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.