简体   繁体   English

Windows Phone 8.1手动更改代码后面的资源文件

[英]Windows Phone 8.1 manually change resource file in code behind

I'm developing application which requires for me to handle multiculture and resources in Windows Phone 8.1. 我正在开发应用程序,这需要我在Windows Phone 8.1中处理多文化和资源。

Currently it loads en language if my phone language is set to english, if I change it to french or whatever it also works. 目前,如果我将手机语言设置为英语,如果我将其更改为法语或其他任何有效的语言,则会加载语言。 What i would like to do is for a user to be able to change the language in the app while not changing the language in the phone. 我想做的是让用户能够在不改变手机语言的同时更改应用程序中的语言。 I would like to have a settings page when user can pick language from a list of possibilities. 当用户可以从可能的列表中选择语言时,我想有一个设置页面。 Save it in some storage settings and after application start to load appropriate resources. 将其保存在某些存储设置中,并在应用程序启动后加载适当的资源。

What I can't figure out is how to load specific resources based on some settings in the storage. 我无法弄清楚的是如何根据存储中的某些设置加载特定资源。

Use IsolatedStorage to store the user selected language string. 使用IsolatedStorage存储用户选择的语言字符串。

When the app is loaded you can change the language to that selected by user using the 加载应用程序后,您可以使用以下语言将语言更改为用户选择的语言

Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride

Property. 属性。

Let me give you some details. 我来详细介绍一下。 Create a class as LacalizedStrings.cs in your project. 在项目中创建一个类LacalizedStrings.cs And let's put that the resource file name is AppResources 让我们说资源文件名是AppResources

public class LocalizedStrings
    {
        private static AppResources _localizedResources = new AppResources();
        public AppResources LocalizedResources { get { return _localizedResources; } }
    }

in your AppResources put one key as ResourceLanguage and value as en-US . 在您的AppResources将一个键设置为ResourceLanguage ,将值设置为en-US

Now this value you can save in IsolatedStorage and the time of 现在这个值可以保存在IsolatedStorage和时间中

private void Application_Launching(object sender, LaunchingEventArgs e)
{
}

or 要么

private void Application_Activated(object sender, ActivatedEventArgs e)
{
}

you can check this value from IsolatedStorage and use it. 您可以从IsolatedStorage检查此值并使用它。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM