/// <summary>
        /// Returns the value of the string resource.
        /// </summary>
        /// <param name="serviceProvider">Object that can provide services for the markup extension.</param>
        /// <returns>The string value.</returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            string value = "";

            IProvideValueTarget target = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));

            if (target != null)
            {
                DependencyObject d = (DependencyObject)target.TargetObject;
                if (d != null)
                {
                    if (!String.IsNullOrEmpty(_assemblyName) && !String.IsNullOrEmpty(_baseName))
                    {
                        value = ResourceStringCoordinator.InitializeValue(
                            d,
                            target.TargetProperty,
                            _assemblyName,
                            _baseName,
                            _name);
                    }
                    else
                    {
                        value = ResourceStringDecorator.InitializeValue(
                            d,
                            target.TargetProperty,
                            _name);
                    }
                }
            }
            return(value);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the value of the string resource.
        /// </summary>
        /// <param name="serviceProvider">Object that can provide services for the markup extension.</param>
        /// <returns>The string value.</returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            string value = "";

            IProvideValueTarget target = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));

            if (target != null)
            {
                DependencyObject d = (DependencyObject)target.TargetObject;
                if (d != null)
                {
                    ResourceManager rm = ResourceStringDecorator.GetResourceManager(d);
                    if (rm != null)
                    {
                        value = rm.GetString(_name);
                    }
                }
            }
            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);
        }