public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string key             = KeyProvider.ProvideKey(new[] { value });
            var    cultureInfo     = value as CultureInfo;
            object localizedObject = CommonResourceManager.Instance.GetResourceObject(key, cultureInfo);

            return(localizedObject ?? ResXExtension.GetDefaultValue(key));
        }
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var resXKeyParts = new List <object>();
            var resXParams   = new List <object>();

            for (int i = 0; i < Parameters.Count; i++)
            {
                object value = values[i];

                BindingBase param = Parameters[i];

                if (param is ResXKeyPart)
                {
                    if (value == DependencyProperty.UnsetValue && param.FallbackValue != null)
                    {
                        value = param.FallbackValue;
                    }
                    if (value != null)
                    {
                        resXKeyParts.Add(value);
                    }
                }
                else if (param is ResXParam)
                {
                    resXParams.Add(value);
                }
            }

            CultureInfo cultureInfo = values[values.Length - 1] as CultureInfo;

            string key = KeyProvider.ProvideKey(resXKeyParts);

            object localizedObject = CommonResourceManager.Instance.GetResourceObject(key, cultureInfo) ??
                                     CommonResourceManager.Instance.GetResourceObject(ResXExtension.Key, cultureInfo);

            if (localizedObject == null)
            {
                localizedObject = ResXExtension.GetDefaultValue(key);
            }
            else
            {
                try
                {
                    localizedObject = string.Format(localizedObject.ToString(), resXParams.Cast <object>().ToArray());
                }
                catch
                {
                }
            }

            return(localizedObject);
        }
        public static void BindExtension(DependencyObject element, DependencyProperty property, string key, IEnumerable <ResXParamBase> resXParams)
        {
            if (element == null || property == null || key == null)
            {
                return;
            }

            var resX = new ResXExtension(key, string.Empty)
            {
                innerElement  = new WeakReference(element),
                innerProperty = property
            };

            if (resXParams != null)
            {
                resX.Parameters.AddRange(resXParams);
            }

            element.SetValue(property, resX.ProvideValue(resX));
        }