/// <summary>
        /// Provides the value.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <returns>the value</returns>
        public override object ProvideValue(System.IServiceProvider serviceProvider)
        {
            object           property;
            FrameworkElement element;

            if (LocalizationBase.TryGetTarget(serviceProvider, out element, out property))
            {
                if (property is DependencyProperty)
                {
                    var context = new LocalizedBinding(element, this.PropertyPath);

                    Application.Current.Dispatcher.BeginInvoke(
                        new Action(() => element.SetBinding(
                                       (DependencyProperty)property,
                                       new Binding
                    {
                        Source = context,
                        Path   = new PropertyPath("Localized.Value"),
                        Mode   = BindingMode.OneWay
                    })));
                }

                var key = this.GetKey(element);

                if (!string.IsNullOrWhiteSpace(key))
                {
                    LocalizedString localized = Localizer.GetString(key);
                    return(localized.Value);
                }

                return(null);
            }

            return(this);
        }
Esempio n. 2
0
 /// <summary>
 /// Gets the key.
 /// </summary>
 /// <param name="contextObject">The context.</param>
 /// <returns>key stored in context property</returns>
 private string GetKey(object contextObject)
 {
     return(LocalizedBinding.ResolveKey(contextObject, this.propertyPath));
 }
 /// <summary>
 /// Gets the key.
 /// </summary>
 /// <param name="element">The framework element.</param>
 /// <returns>key or null</returns>
 private string GetKey(FrameworkElement element)
 {
     return(LocalizedBinding.ResolveKey(element.DataContext, this.PropertyPath));
 }