title: Access Application Localization resources (resx) from Library
body: <p>I've seen the solution suggested here: <a href="https://stackoverflow.com/questions/8384851/access-resx-in-application-from-silverlight-class-library/10257261#10257261">Access resx in application from Silverlight class library</a>
  and it works for the resources itself.</p>
  
  <p>My problem is slightly different:</p>
  
  <ol>
  <li>I have 2 apps that use the same library. They are localized so I have a resource folder and in the folder of the apps the files AppResource.resx, AppResource.it-IT.resx</li>
  <li>I have a library that includes XAML files and code as well. It is localized so I have a resource folder and in the folder of the apps the files LibResource.resx, LibResource.it-IT.resx</li>
  <li>The app is using the MvvmLight libraries. As suggested I've extended the class
  ViewModelBase in a ViewModelBaseExtended adding the fields:</li>
  </ol>
  
  <pre class="lang-cs prettyprint-override"><code>public class ViewModelBaseExtended : ViewModelBase
  {
      private static LibResources resources = new LibResources();
      public LibResources Resources { get { return resources; } }
  }
  </code></pre>
  
  <ol start="4">
  <li>The XAML in the library is able to access correctly the localized resources:</li>
  </ol>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;phone:PhoneApplicationPage x:Class="PhoneClassLibrary1.MainPage"
             DataContext="{Binding Main, Source={StaticResource Locator}}"&gt;
  
  &lt;StackPanel x:Name="TitlePanel"
  Grid.Row="0"
  Margin="24,24,0,12"&gt;
             &lt;TextBlock x:Name="ApplicationTitle"
                  Text="{Binding Resources.AppName}"
                  Style="{StaticResource PhoneTextNormalStyle}" /&gt;
             &lt;TextBlock x:Name="PageTitle"
                  Text="{Binding Resources.LocalLib}"
                  Margin="-3,-8,0,0"
                  Style="{StaticResource PhoneTextTitle1Style}" /&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>My problem is: how can I access from the library the AppResources in the application?
  I cannot refer to them directly Namespace.AppResources as the library is shared between applications and Namespace is not defined at design time and changes at run time.</p>
  
  <p>I have a full project ready to test with the exact configruation, files etxc.. all working apart from the access from library to application level.</p>
  
  <p>Applying the solution I mentioned in the beginning:</p>
  
  <pre class="lang-cs prettyprint-override"><code>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);
  }
  </code></pre>
  
  <p>I correctly does not compile with an error as gResources is an AppResource (or LibResource) class while ResourceManager returns a different object.</p>