Skip to content

Instantly share code, notes, and snippets.

@cjlotz
Last active December 20, 2015 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjlotz/6051474 to your computer and use it in GitHub Desktop.
Save cjlotz/6051474 to your computer and use it in GitHub Desktop.
PivotViewerResourceManager
public class PivotViewerResourceManager : ResourceManager
{
public const string PivotViewerResourcePrefix = "MSPivot";
private PivotViewerResourceManager(IResourceProvider provider) : base("System.Windows.Controls.Pivot.Properties.Resources", typeof(PivotViewer).Assembly)
{
ResourceProvider = provider;
}
private IResourceProvider ResourceProvider { get; set; }
public override string GetString(string name, CultureInfo culture)
{
string resourceString = null;
// First attempt reading the "MSPivot" prefixed resources from any external provider
if (ResourceProvider != null)
resourceString = ResourceProvider.GetString(PivotViewerResourcePrefix + name, culture);
// If no external resource value found, read from the base MS pivot viewer resource file
if (string.IsNullOrEmpty(resourceString))
resourceString = base.GetString(name, culture);
return resourceString;
}
public static void InjectResourceManager(IResourceProvider provider)
{
Check.ArgumentNotNull(provider, "provider");
Type resources = typeof(PivotViewer).Assembly.GetType("System.Windows.Controls.Pivot.Properties.Resources");
FieldInfo fieldInfo = resources.GetField("resourceMan", BindingFlags.Static | BindingFlags.NonPublic);
fieldInfo.SetValue(null, new PivotViewerResourceManager(provider));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment