Using String in AppResources

I use LocalizedResourcesto get localization for my WP 8.1 application. But if I used this code:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    string xyz = string.Empty;
    NavigationContext.QueryString.TryGetValue("znam", out xyz);
    tekstZnamenitosti.Text = AppResources.tekstTrsat;
}

then I should have many if statements to test each znamenitost. Is there any way to use

tekstZnamenitosti.Text = AppResources.xyz;

where xyz is the line I made earlier, and in it is the value passed from the page from which I went.

+4
source share
3 answers

You can get the value AppResourcesusing the ResourceManager :

tekstZnamenitosti.Text = AppResources.ResourceManager.GetString("xyz");
+3
source

(+1) - , - :

:

namespace YourNamespace
{
  public class AppRes
  {
    private static ResourceLoader load = new ResourceLoader();
    private static string GetProperty([CallerMemberName] string propertyName = null) { return propertyName; }

    public static string PropertyName { get { return load.GetString(GetProperty()); } }
  }
}

App.xaml :

<Application.Resources>
    <local:AppRes x:Key="Localized"/>
    // ... rest of the code.

:

string fromResources = AppRes.PropertyName;

XAML:

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

, , - Resource.resw, :

public static string NewPropertyName { get { return load.GetString(GetProperty()); } }
+2

, App.xaml.cs,

 public static string xyz;

, , , App.xaml.cs.

tekstZnamenitosti.Text = App.xyx;

.

0

Source: https://habr.com/ru/post/1544862/


All Articles