C# 在AppResources中使用字符串

C# 在AppResources中使用字符串,c#,windows-phone,windows-phone-8.1,C#,Windows Phone,Windows Phone 8.1,我正在使用LocalizedResources获取我的WP 8.1应用程序的本地化。但如果我使用这样的代码: protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { string xyz = string.Empty; NavigationContext.QueryString.TryGetValue("znam", out xyz); tekstZn

我正在使用
LocalizedResources
获取我的WP 8.1应用程序的本地化。但如果我使用这样的代码:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    string xyz = string.Empty;
    NavigationContext.QueryString.TryGetValue("znam", out xyz);
    tekstZnamenitosti.Text = AppResources.tekstTrsat;
}
然后我必须有许多if语句来检查每个
znametitost
。有什么方法可以使用它吗

tekstZnamenitosti.Text = AppResources.xyz;

其中xyz是我之前创建的字符串,其中是从我导航的页面传递的值。

您可以使用ResourceManager获得
AppResources
值:

tekstZnamenitosti.Text = AppResources.ResourceManager.GetString("xyz");
仅扩展(+1)一点-也许有人会发现它很有用:

为您的资源创建特殊类:

在App.xaml中,向资源添加密钥:

在XAML中:

<TextBlock Text="{Binding PropertyName, Source={StaticResource Localized}}" ...

是的,您可以在
App.xaml.cs
中使用字符串值,例如

 public static string xyz;
然后,您可以将想要的值保存到在App.xaml.cs中创建的变量中

tekstZnamenitosti.Text = App.xyx;

您可以在应用程序中的任何位置使用此变量

不客气。如果对你有帮助,请将其标记为答案。所以更多的人可以得到它。谢谢!谢谢你提醒我:)我试过了,但它说要等8分钟,我忘了!谢谢你的扩展!(+1)
<TextBlock Text="{Binding PropertyName, Source={StaticResource Localized}}" ...
public static string NewPropertyName { get { return load.GetString(GetProperty()); } }
 public static string xyz;
tekstZnamenitosti.Text = App.xyx;