Access to access localization resources (resx) from the library

I saw the solution offered here: Access resx in the application from the Silverlight class library and it works for the resources themselves.

My problem is slightly different:

  • I have 2 applications that use the same library. They are localized, so I have a folder with resources, and in the application folder there are files AppResource.resx, AppResource.it-IT.resx
  • I have a library that also contains XAML files and code. It is localized, so I have a folder with resources and in the application folder are the files LibResource.resx, LibResource.it-IT.resx
  • The application uses the MvvmLight libraries. As I proposed to extend the ViewModelBase class in ViewModelBaseExtended with the addition of fields:
public class ViewModelBaseExtended : ViewModelBase
{
    private static LibResources resources = new LibResources();
    public LibResources Resources { get { return resources; } }
}
  1. XAML :
<phone:PhoneApplicationPage x:Class="PhoneClassLibrary1.MainPage"
           DataContext="{Binding Main, Source={StaticResource Locator}}">

<StackPanel x:Name="TitlePanel"
Grid.Row="0"
Margin="24,24,0,12">
           <TextBlock x:Name="ApplicationTitle"
                Text="{Binding Resources.AppName}"
                Style="{StaticResource PhoneTextNormalStyle}" />
           <TextBlock x:Name="PageTitle"
                Text="{Binding Resources.LocalLib}"
                Margin="-3,-8,0,0"
                Style="{StaticResource PhoneTextTitle1Style}" />
</StackPanel>

: AppResources ? . Namespace.AppResources, , .

, configruation, etxc.. .

, :

private static AppResources _gResources;
public AppResources gResources { set {_gResources = value;}  get { return _gResources; } }

public ViewModelBaseExtended()
{
    var assembly = Application.Current.GetType().Assembly;
    var ast = assembly.FullName;
    char[] delimit = new char[] { ',' };
    string[] parts = ast.Split(delimit);

    gResources = new System.Resources.ResourceManager(parts[0]+ ".AppResources", assembly);
}

, gResources - AppResource ( LibResource), ResourceManager .

+3

All Articles