/// <summary> /// Returns a resource string value /// and registers the property /// so It may be refreshed /// (by ResourceStringDecorator.Refresh()) after a current culture change /// </summary> /// <param name="d">The object which owns the property.</param> /// <param name="property">The property object. It may be a DependencyProperty (WPF property) or a PropertyInfo (CLR property).</param> /// <param name="assemblyName">The name of the assembly containing the baseName resx file for localization.</param> /// <param name="baseName">The resx file base name for localization.</param> /// <param name="resourceName">The name of the resource.</param> /// <returns>The resource string value.</returns> internal static string InitializeValue( DependencyObject d, object property, string assemblyName, string baseName, string resourceName) { string value = ""; ResourceSetManager rsm = GetManager(assemblyName, baseName); value = rsm.ResourceManager.GetString(resourceName); // Register (links) the property value to the ResourceSetManager.LocalizedObjects collection // so the ResourceStringCoordinator may refresh the property value // (by the Refresh() method) after a current culture change if (property is DependencyProperty) { DepPropResourceLink dprl = new DepPropResourceLink( d, resourceName, (DependencyProperty)property); rsm.LocalizedObjects.Add(dprl); } if (property is PropertyInfo) { ClrPropResourceLink cprl = new ClrPropResourceLink( d, resourceName, (PropertyInfo)property); rsm.LocalizedObjects.Add(cprl); } return(value); }
/// <summary> /// Returns a resource string value /// and registers the property /// so It may be refreshed /// (by ResourceStringDecorator.Refresh()) after a current culture change /// </summary> /// <param name="d">The object which owns the property.</param> /// <param name="property">The property object. It may be a DependencyProperty (WPF property) or a PropertyInfo (CLR property).</param> /// <param name="resourceName">The name of the resource.</param> /// <returns>The resource string value.</returns> public static string InitializeValue( DependencyObject d, object property, string resourceName) { string value = ""; ResourceManager rm = ResourceStringDecorator.GetResourceManager(d); if (rm != null) { // Console.WriteLine("RSD : CurrentUICulture {0}.", System.Globalization.CultureInfo.CurrentUICulture.Name); value = rm.GetString(resourceName); // Register (links) the property value to the ResourceStringDecorator.LocalizedChildren dictionary // so the ResourceStringDecorator may refresh the property value // (by ResourceStringDecorator.Refresh()) after a current culture change List <ResourceLink> localizedChildren = ResourceStringDecorator.GetLocalizedChildren(d); if (localizedChildren != null) { if (property is DependencyProperty) { DepPropResourceLink dprl = new DepPropResourceLink( d, resourceName, (DependencyProperty)property); localizedChildren.Add(dprl); } if (property is PropertyInfo) { ClrPropResourceLink cprl = new ClrPropResourceLink( d, resourceName, (PropertyInfo)property); localizedChildren.Add(cprl); } } } return(value); }