public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var pvt = serviceProvider as IProvideValueTarget;
            if (pvt == null)
            {
                return null;
            }

            _frameworkElement = pvt.TargetObject as FrameworkElement;
            if (_frameworkElement == null)
            {
                return this;
            }

            _target = pvt.TargetProperty as DependencyProperty;
            if (_target == null)
            {
                return this;
            }

            _frameworkElement.DataContextChanged += FrameworkElement_DataContextChanged;

            var proxy = new Proxy();
            var binding = new Binding()
            {
                Source = proxy,
                Path = new PropertyPath("Value")
            };

            // Make sure we don't leak subscriptions
            _frameworkElement.Unloaded += (e, v) => _subscription.Dispose();

            return binding.ProvideValue(serviceProvider);
        }
Example #2
0
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     var binding = new Binding("Value")
                       {
                           Source = new TranslationSource(_key)
                       };
     return binding.ProvideValue(serviceProvider);
 }
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     var binding = new Binding("SelectedCulture[" + Id + "]")
     {
         Source = GlobalizationUtilities.TheInstance
     };
     return binding.ProvideValue(serviceProvider);
 }
Example #4
0
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     var binding = new Binding("Value")
     {
         Source = new FontFamilyData { Culture = _culture }
     };
     return binding.ProvideValue(serviceProvider);
 }
        public override object ProvideValue(IServiceProvider rpServiceProvider)
        {
            var rBinding = new Binding(r_Path) { Source = Preference.Current, Mode = BindingMode.TwoWay, Converter = Converter, ConverterParameter = ConverterParameter, UpdateSourceTrigger = UpdateSourceTrigger };
            if (ValidationRule != null)
                rBinding.ValidationRules.Add(ValidationRule);

            return rBinding.ProvideValue(rpServiceProvider);
        }
Example #6
0
    public override object ProvideValue(IServiceProvider serviceProvider)
    {
      if (IsDesignMode)
        return Key;

      var binding = new Binding("Value") {Source = new LocalizationData(_key)};
      return binding.ProvideValue(serviceProvider);
    }
Example #7
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            Binding bind = new Binding("Value");
            bind.Path=new PropertyPath(Value);
            bind.Mode=BindingMode.TwoWay;
            bind.Source = vm;

            return bind.ProvideValue(serviceProvider);
        }
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     var binding = new Binding("Value")
           {
               Source = new TranslationBinding(_key, _default),
               Mode = BindingMode.OneWay
           };
     return binding.ProvideValue(serviceProvider);
 }
		public override object ProvideValue(IServiceProvider serviceProvider)
		{
			if (UpdateOnLanguageChange) {
				Binding binding = new Binding("Value") { Source = this, Mode = BindingMode.OneWay };
				return binding.ProvideValue(serviceProvider);
			} else {
				return this.Value;
			}
		}
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     var counter = new Counter();
     var binding = new Binding(nameof(counter.Value))
     {
         Source = counter,
         Mode = BindingMode.OneWay,
         UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
     };
     return binding.ProvideValue(serviceProvider);
 }
        public override object ProvideValue(IServiceProvider rpServiceProvider)
        {
            if (DesignerProperties.GetIsInDesignMode(r_DesignModeDetector))
                return DependencyProperty.UnsetValue;

            var rBinding = new Binding(r_Path) { Source = Preference.Instance, Mode = BindingMode.TwoWay, Converter = Converter, ConverterParameter = ConverterParameter, UpdateSourceTrigger = UpdateSourceTrigger, StringFormat = StringFormat };
            if (ValidationRule != null)
                rBinding.ValidationRules.Add(ValidationRule);

            return rBinding.ProvideValue(rpServiceProvider);
        }
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     var instance = DesignTimeValue.Instance;
     var binding = new Binding(nameof(instance.CurrentValue))
     {
         Source = instance,
         Mode = BindingMode.OneWay,
         UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
     };
     return binding.ProvideValue(serviceProvider);
 }
        /// <inheritdoc />
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var binding = new Binding()
            {
                Source = EffectiveCultureProxy.Instance,
                Path = ValuePath,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Mode = BindingMode.OneWay,
                Converter = CultureToXmlLanguageConverter.Default
            };

            return binding.ProvideValue(serviceProvider);
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var rootObjectProvider = (IRootObjectProvider) serviceProvider.GetService(typeof (IRootObjectProvider));
            var binding = new Binding
            {
                Path = DataContextPath,
                Source = rootObjectProvider?.RootObject,
                Mode = BindingMode.OneWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            };

            return binding.ProvideValue(serviceProvider);
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            IProvideValueTarget target = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;

            if (target.TargetObject is Setter)
            {
                return new Binding(Path) { Converter = ImgaeResourceConverter.Default };
            }
            else
            {
                Binding binding = new Binding(Path) { Converter = ImgaeResourceConverter.Default };
                return binding.ProvideValue(serviceProvider);
            }
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            string propertyPath;
            if (ThemePalette.TryGetResource(this.Resource, out propertyPath))
            {
                Binding binding = new Binding(propertyPath)
                {
                    Source = ThemePalette.Palette,
                    Converter = new ColorToSolidColorBrushConverter(),
                    Mode = BindingMode.OneWay
                };
                return binding.ProvideValue(serviceProvider);
            }

            return null;
        }
Example #17
0
        // Fournit la valeur au XAML
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            // En design time ou renvoie la clé préfixé de #DesignTime#
            bool designTime = System.ComponentModel.DesignerProperties.GetIsInDesignMode(new DependencyObject());
            if (designTime)
            {
                return "#DesignTime#" + Key;
            }
            else
            {
                // On checrcher le service de langue
                IUnityContainer container = ServiceLocator.Current.GetInstance<IUnityContainer>();
                if (container != null)
                {
                    ITranslateService translateService = container.TryResolve<ITranslateService>();
                    if (translateService != null)
                    {
                        // On cré le binding
                        var binding = new Binding("[" + _key+"]")
                        {
                            Source = translateService,
                            UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                            Mode= BindingMode.OneWay
                        }
                        ;
                        return binding.ProvideValue(serviceProvider);

                    }
                    return NoLangServiceError;
                }
                else return NoLangServiceError;
            }
        }
        private object bindDictionary(IServiceProvider serviceProvider)
        {
            string uid = _uid ?? GetUid(_target);
            string vid = _property.Name;

            var binding = new Binding("Dictionary") {Source = LanguageContext.Current, Mode = BindingMode.TwoWay};
            var converter = new LanguageConverter(uid, vid, _default);
            if (_parameters.Count == 0)
            {
                binding.Converter = converter;
                object value = binding.ProvideValue(serviceProvider);
                return value;
            }
            else
            {
                var multiBinding = new MultiBinding {Mode = BindingMode.TwoWay, Converter = converter};
                multiBinding.Bindings.Add(binding);
                if (string.IsNullOrEmpty(uid))
                {
                    var uidBinding = _parameters[0] as Binding;
                    if (uidBinding == null)
                    {
                        throw new ArgumentException("Uid Binding parameter must be the first, and of type Binding");
                    }
                }
                foreach (Binding parameter in _parameters)
                {
                    multiBinding.Bindings.Add(parameter);
                }
                object value = multiBinding.ProvideValue(serviceProvider);
                return value;
            }
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (Key != null && KeyBinding != null)
                throw new ArgumentException($"Нельзя одновременно задать {nameof(Key)} и {nameof(KeyBinding)}");
            if (Key == null && KeyBinding == null)
                throw new ArgumentException($"Необходимо задать {nameof(Key)} или {nameof(KeyBinding)}");
            if (Arguments != null && ArgumentBindings.Any())
                throw new ArgumentException($"Нельзя одновременно задать {nameof(Arguments)} и {nameof(ArgumentBindings)}");

            var target = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));
            if (target.TargetObject.GetType().FullName == "System.Windows.SharedDp")
                return this;

            // Если заданы привязка ключа или список привязок аргументов,
            // то используем BindingLocalizationListener
            if (KeyBinding != null || ArgumentBindings.Any())
            {
                var listener = new BindingLocalizationListener();

                // Создаем привязку для слушателя
                var listenerBinding = new Binding { Source = listener };

                var keyBinding = KeyBinding ?? new Binding { Source = Key };

                var multiBinding = new MultiBinding
                {
                    Converter = new BindingLocalizationConverter(),
                    ConverterParameter = Arguments,
                    Bindings = { listenerBinding, keyBinding }
                };

                // Добавляем все переданные привязки аргументов
                foreach (var binding in ArgumentBindings)
                    multiBinding.Bindings.Add(binding);

                var value = multiBinding.ProvideValue(serviceProvider);
                // Сохраняем выражение привязки в слушателе
                listener.SetBinding(value as BindingExpressionBase);
                return value;
            }

            // Если задан ключ, то используем KeyLocalizationListener
            if (!string.IsNullOrEmpty(Key))
            {
                var listener = new KeyLocalizationListener(Key, Arguments?.ToArray());

                // Если локализация навешана на DependencyProperty объекта DependencyObject
                if ((target.TargetObject is DependencyObject && target.TargetProperty is DependencyProperty) ||
                    target.TargetObject is Setter)
                {
                    var binding = new Binding(nameof(KeyLocalizationListener.Value))
                    {
                        Source = listener,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    };
                    return binding.ProvideValue(serviceProvider);
                }

                // Если локализация навешана на Binding, то возвращаем слушателя
                var targetBinding = target.TargetObject as Binding;
                if (targetBinding != null && target.TargetProperty != null &&
                    target.TargetProperty.GetType().FullName == "System.Reflection.RuntimePropertyInfo")
                {
                    targetBinding.Path = new PropertyPath(nameof(KeyLocalizationListener.Value));
                    targetBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                    return listener;
                }

                // Иначе возвращаем локализованную строку
                return listener.Value;
            }

            return null;
        }
 /// <summary>
 /// See <see cref="MarkupExtension.ProvideValue" />
 /// </summary>
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     var binding = new Binding("Value")
     {
         Source = new TranslationData
         {
             Key = _key,
             Format = _format,
             Mode = _mode,
             Culture = _culture
         }
     };
     return binding.ProvideValue(serviceProvider);
 }
        internal static object CreateBindingExpression(ResourceManager resourceManager, string key, IServiceProvider serviceProvider)
        {
            var errorHandling = ErrorHandling.GetMode(serviceProvider.ProvideValueTarget()?.TargetObject as DependencyObject) ??
                                              Gu.Localization.ErrorHandling.ReturnErrorInfo;
            var translation = Gu.Localization.Translation.GetOrCreate(resourceManager, key, errorHandling);
            var binding = new Binding
            {
                Path = TranslatedPropertyPath,
                Mode = BindingMode.OneWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Source = translation
            };

            var provideValue = binding.ProvideValue(serviceProvider);
            return provideValue;
        }
Example #22
0
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     var binding = new Binding("Value") { Source = new LocalizedBindingSource(key) };
       return binding.ProvideValue(serviceProvider);
 }
Example #23
0
 public override object ProvideValue(IServiceProvider provider)
 {
     var binding = new Binding("Value");
     binding.Source = new ResourceData(this.Key);
     return binding.ProvideValue(provider);
 }
Example #24
0
		public override object ProvideValue()
		{
			var target = XamlObject.Instance as Binding;
			//TODO: XamlObject.Clone()
			var b = new Binding();
			foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(target)) {
				if (pd.IsReadOnly) continue;
				try {
					var val1 = pd.GetValue(b);
					var val2 = pd.GetValue(target);
					if (object.Equals(val1, val2)) continue;
					pd.SetValue(b, val2);
				} catch {}
			}
			return b.ProvideValue(XamlObject.ServiceProvider);
		}
Example #25
0
 /// <summary>
 /// See <see cref="MarkupExtension.ProvideValue" />
 /// </summary>
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     Binding binding = new Binding("Value");
     binding.Source = new TranslationData(key);
     return binding.ProvideValue(serviceProvider);
 }
        public override object FormatOutput(TargetInfo endPoint, TargetInfo info)
        {
            //if (!info.IsDependencyObject)
            //    throw new NotSupportedException("A Binding can only be applied to a DependencyObject!");

            if (endPoint == null)
                return null;

            DependencyObject obj = (DependencyObject)endPoint.TargetObject;
            Binding binding = new Binding();
            object src = source;

            if ((src == null) || (".".CompareTo(src) == 0))
            {
                if (obj is FrameworkElement)
                    src = ((FrameworkElement)obj).DataContext;
#if SILVERLIGHT
#else
                else if (obj is FrameworkContentElement)
                    src = ((FrameworkContentElement)obj).DataContext;
#endif

                if (src == null)
                    return null;
                    //throw new ArgumentNullException("Neither a source was specified, nor it could be retrieved from the DataContext!");
            }

            if (String.IsNullOrEmpty(path) || String.IsNullOrEmpty(path.Trim()))
                return null;
                //throw new ArgumentNullException("No path was specified!");

            binding.Source = src;
            binding.Path = new PropertyPath(path);
            binding.Converter = converter;
            binding.ConverterParameter = converterParameter;

            object ret = null;

            if (info.IsDependencyObject)
                ret = binding.ProvideValue(new SimpleProvideValueServiceProvider(endPoint.TargetObject, endPoint.TargetProperty, endPoint.TargetPropertyType, endPoint.TargetPropertyIndex));
            else
            {
                BindingProxy proxy = new BindingProxy();
                proxy.Source = binding.ProvideValue(new SimpleProvideValueServiceProvider(proxy, BindingProxy.SourceProperty, null, -1));
                proxy.Target = info;
                ret = proxy.TargetValue;
            }

            return ret;
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (this.Converter == null && this.TargetType == null)
            {
                var target = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
                if (target == null)
                {
                    return this;
                }

                var prop = target.TargetProperty as DependencyProperty;
                if (prop == null)
                {
                    return this;
                }

                this.TargetType = prop.PropertyType;
            }

            var binding = new Binding
            {
                Source = Theme.Instance,
                Path = new PropertyPath("Theme." + this.Path),
                Converter = this,
            };

            return binding.ProvideValue(serviceProvider);
        }