示例#1
0
        /// <summary>
        /// Provides the value of the converter.
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (TimeBinding == null)
            {
                throw new ArgumentNullException("TimeBinding");
            }

            // Always create a dummy binding to be notified when the translation dictionary changes.
            Binding binding = new Binding("Dummy");

            binding.Source = DictionaryWatcher.Instance;
            binding.Mode   = BindingMode.OneWay;

            Binding timerBinding = new Binding("Dummy");

            timerBinding.Source = UpdateTimer.Instance;
            timerBinding.Mode   = BindingMode.OneWay;

            MultiBinding multiBinding = new MultiBinding();

            multiBinding.Mode = BindingMode.TwoWay;

            // Add the dummy binding as well as the binding for the number value.
            multiBinding.Bindings.Add(binding);
            multiBinding.Bindings.Add(timerBinding);
            multiBinding.Bindings.Add(TimeBinding);

            // The converter will invoke the actual formatting of the value.
            multiBinding.Converter = new TimeConverter(RelativeTimeKind, UpperCase);
            return(multiBinding.ProvideValue(serviceProvider));
        }
示例#2
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (string.IsNullOrEmpty(ReplacementKey))
            {
                throw new InvalidOperationException("The key property cannot be null or empty");
            }


            // --- On crée une nouvelle liaison autonome
            var multiBinding = new MultiBinding()
            {
                Converter = Converter,
            };

            multiBinding.Bindings.Add(Property);
            multiBinding.Bindings.Add
            (
                new Binding("Value")
            {
                Source = new DataModule(ReplacementKey),
            }
            );

            return(multiBinding.ProvideValue(serviceProvider));
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var provideValueTarget = serviceProvider as IProvideValueTarget;
            var targetObject       = provideValueTarget?.TargetObject as FrameworkElement;
            var targetProperty     = provideValueTarget?.TargetProperty as DependencyProperty;
            var alternativeKey     = $"{targetObject?.Name}_{targetProperty?.Name}";

            var multiBinding = new MultiBinding
            {
                Converter             = new LocalizationConverter(Key, alternativeKey),
                NotifyOnSourceUpdated = true
            };

            multiBinding.Bindings.Add(new Binding
            {
                Source = LocalizationManager.Instance,
                Path   = new PropertyPath("CurrentCulture")
            });

            if (KeySource != null)
            {
                multiBinding.Bindings.Add(KeySource);
            }

            if (CountSource != null)
            {
                multiBinding.Bindings.Add(CountSource);
            }

            return(multiBinding.ProvideValue(serviceProvider));
        }
        /// <summary>
        /// Returns the value for this instance of the Markup Extension.
        /// </summary>
        /// <param name="serviceProvider">The service provider</param>
        /// <returns>The value of the element</returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            // Register the target and property so we can update them.
            RegisterTarget(serviceProvider);

            if (String.IsNullOrEmpty(Key) && !IsBindingExpression)
            {
                throw new ArgumentException("You must set the resource Key or Binding properties");
            }

            // If the extension is used in a template or as a child of another
            // extension (for multi-binding) then return this.
            if (TargetProperty == null || IsMultiBindingChild)
            {
                return(this);
            }

            // If this extension has child Resx elements then invoke AFTER this method has returned
            // to setup the MultiBinding on the target element.
            if (IsMultiBindingParent)
            {
                MultiBinding binding = CreateMultiBinding();
                return(binding.ProvideValue(serviceProvider));
            }

            if (IsBindingExpression)
            {
                // If this is a simple binding then return the binding.
                Binding binding = CreateBinding();
                return(binding.ProvideValue(serviceProvider));
            }

            // Otherwise, return the value from the resources.
            return(GetValue());
        }
示例#5
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (!(serviceProvider.GetService(typeof(IProvideValueTarget)) is IProvideValueTarget pvt))
            {
                return(null);
            }

            if (!(pvt.TargetObject is DependencyObject targetObject))
            {
                return(null);
            }

            if (!(pvt.TargetProperty is DependencyProperty targetProperty))
            {
                return(null);
            }

            var binding = new MultiBinding
            {
                Converter          = new LocalizationConverter(),
                ConverterCulture   = Locator.LocalizationManager.CurrentCulture,
                ConverterParameter = Key
            };

            binding.Bindings.Add(new Binding {
                Path = new PropertyPath("(0)", typeof(ILocalizationManager).GetProperty(nameof(ILocalizationManager.CurrentCulture)))
            });

            var expression = BindingOperations.SetBinding(targetObject, targetProperty, binding);

            return(binding.ProvideValue(serviceProvider));
        }
示例#6
0
        /// <summary>
        /// Return the value for this instance of the Markup Extension
        /// </summary>
        /// <param name="serviceProvider">The service provider</param>
        /// <returns>The value of the element</returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            // Register the target and property so we can update them
            RegisterTarget(serviceProvider);

            if (string.IsNullOrEmpty(this.Key) && !this.IsBound)
            {
                throw new ArgumentException("Resource key is missing and no binding defined.");
            }

            // When the extension has no target (used in a template)
            // (Also occurs when used as a child element in .NET 4+)
            if (base.TargetProperty == null)
            {
                return(this);
            }

            object value = GetValue();

            if (this.IsBound)
            {
                MultiBinding wrapper = CreateMultiBindingWrapper(value);

                value = wrapper.ProvideValue(serviceProvider);
            }

            return(value);
        }
示例#7
0
        /// <summary>
        /// When implemented in a derived class, returns an object that is provided as the value of the target property for this markup extension.
        /// </summary>
        /// <param name="serviceProvider">A service provider helper that can provide services for the markup extension.</param>
        /// <returns>The object value to set on the property where the extension is applied.</returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            if (Binding == null)
            {
                return(null);
            }

            var multiBinding = new MultiBinding
            {
                Converter = FirstValueConverter.Instance
            };

            multiBinding.Bindings.Add(Binding);
            multiBinding.Bindings.Add
            (
                new Binding(nameof(NotificationBindingSource.Group))
            {
                Source = CreateOrGetNotificationBindingSource(Group),
                Mode   = BindingMode.OneWay,
            }
            );

            return(multiBinding.ProvideValue(serviceProvider));
        }
        public override object ProvideValue(IServiceProvider rpServiceProvider)
        {
            var rResult = new MultiBinding()
            {
                Mode = BindingMode.OneWay, Converter = CoreConverter.Instance
            };

            rResult.Bindings.Add(new Binding()
            {
                Path = new PropertyPath(MetroWindow.ScreenOrientationProperty), RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(MetroWindow), 1)
            });
            rResult.Bindings.Add(new Binding("LandscapeDock.Value")
            {
                Source = Preference.Instance.UI
            });
            rResult.Bindings.Add(new Binding("PortraitDock.Value")
            {
                Source = Preference.Instance.UI
            });
            rResult.Bindings.Add(new Binding()
            {
                RelativeSource = RelativeSource.Self
            });

            if (Converter != null)
            {
                rResult.ConverterParameter = Tuple.Create(Converter, ConverterParameter);
            }

            return(rResult.ProvideValue(rpServiceProvider));
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var binding = new MultiBinding();

            binding.Bindings.Add(this.DictionaryBinding);
            binding.Converter = new ParameterTemplateSelectorConvertor();
            return(binding.ProvideValue(serviceProvider));
        }
        /// <summary>
        /// Retrieves the localized value from resources or by other means.
        /// </summary>
        /// <returns>The localized value.</returns>
        protected override object GetLocalizedValue()
        {
            var obj = Property.Object;

            if (obj == null)
            {
                return(null);
            }

            string formatString;

            if (string.IsNullOrEmpty(_resourceKey))
            {
                formatString = _stringFormat;
            }
            else
            {
                var resourceManager = Property.GetResourceManager();

                string value;

                if (resourceManager == null)
                {
                    value = GetFallbackValue();
                }
                else
                {
                    var uiCulture = Property.GetUICulture();

                    value = resourceManager.GetString(_resourceKey, uiCulture);

                    if (value == null)
                    {
                        value = GetFallbackValue();
                    }
                }

                formatString = value;
            }

            var culture = Property.GetCulture();

            var binding = new MultiBinding()
            {
                StringFormat = formatString,
                Mode         = BindingMode.OneWay,
                // The "MultiBinding" type internally uses the converter culture both
                // with converters and format strings
                ConverterCulture = culture,
            };

            foreach (var item in _bindings)
            {
                binding.Bindings.Add(item);
            }

            return(binding.ProvideValue(this));
        }
示例#11
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (!(serviceProvider.GetService(typeof(IProvideValueTarget)) is IProvideValueTarget service))
            {
                return(this);
            }

            if (!(service.TargetObject is DependencyObject targetObject) ||
                !(service.TargetProperty is DependencyProperty targetProperty))
            {
                return(this);
            }

            IEnumerable <object> providedValues = Collection.Select(tr => tr.ProvideValue(serviceProvider, true) as BindingBase ?? (object)tr);

            if (providedValues.All(p => p is BindingBase))
            {
                var internalConverter = new ForMultiTrMarkupInternalStringFormatMultiValuesConverter()
                {
                    StringFormat              = StringFormat ?? string.Join(Separator, Enumerable.Range(0, Collection.Count).Select(i => "{" + i.ToString() + "}")),
                    MultiTrConverter          = Converter,
                    MultiTrConverterParameter = ConverterParameter,
                    MultiTrConverterCulture   = ConverterCulture,
                };

                MultiBinding multiBinding = new MultiBinding()
                {
                    Converter = internalConverter
                };

                Collection.ToList().ForEach(tr =>
                {
                    BindingBase bindingBase = tr.ProvideValue(serviceProvider, true) as BindingBase;

                    if (bindingBase is MultiBinding trMultiBinding)
                    {
                        trMultiBinding.Bindings.ToList().ForEach(multiBinding.Bindings.Add);
                    }
                    else
                    {
                        multiBinding.Bindings.Add(bindingBase);
                    }

                    internalConverter.StringFormatBindings.Add(bindingBase);
                });

                BindingOperations.SetBinding(targetObject, targetProperty, multiBinding);

                return(multiBinding.ProvideValue(serviceProvider));
            }
            else
            {
                return(this);
            }
        }
示例#12
0
        /// <summary>
        /// Retrieves the localized value from resources or by other means.
        /// </summary>
        /// <returns>The localized value.</returns>
        protected override object GetLocalizedValue()
        {
            var obj = Property.Object;

            if (obj == null)
            {
                return(null);
            }

            string formatString;

            if (string.IsNullOrEmpty(_resourceKey))
            {
                formatString = _stringFormat;
            }
            else
            {
#if DEBUG
                if ((bool)DependencyPropertyDescriptor.FromProperty(DesignerProperties.IsInDesignModeProperty, typeof(DependencyObject)).Metadata.DefaultValue)
                {
                    formatString = Normalize(_resourceKey) ?? GetFallbackValue();
                }
                else
                {
#endif
                if (_resourceKey[0] == '^')
                {
                    var newResourceKey = _resourceKey.Substring(1);
                    formatString = newResourceKey.Localize(Normalize(newResourceKey), LocalizationScope.DefaultCategory) ?? GetFallbackValue();
                }
                else
                {
                    formatString = _resourceKey.Localize(Normalize(_resourceKey), Property.GetCategory()) ?? GetFallbackValue();
                }
#if DEBUG
            }
#endif
            }

            var binding = new MultiBinding()
            {
                StringFormat = formatString,
                Mode         = BindingMode.OneWay,
                // The "MultiBinding" type internally uses the converter culture both
                // with converters and format strings
                ConverterCulture = Property.GetCulture(),
            };

            foreach (var item in _bindings)
            {
                binding.Bindings.Add(item);
            }

            return(binding.ProvideValue(this));
        }
        private object BindDictionary(IServiceProvider serviceProvider)
        {
            string uid = _uid ?? GetUid(_target);
            string vid = _property.Name;

            var proxy   = new BindingProxy();
            var binding = new Binding(nameof(BindingProxy.ProxyProperty));

            binding.Source = proxy;
            binding.Mode   = BindingMode.TwoWay;
            var converter = new LanguageConverter(uid, vid, _default, _namespace);

            if (_parameters.Count == 0)
            {
                if (_binding == null)
                {
                    binding.Converter = converter;
                    object value = binding.ProvideValue(serviceProvider);
                    return(value);
                }
                else
                {
                    if (_binding.Converter == null)
                    {
                        _binding.Converter = converter;
                    }
                    object value = _binding.ProvideValue(serviceProvider);
                    return(value);
                }
            }

            else
            {
                var multiBinding = new MultiBinding();
                multiBinding.Mode      = BindingMode.TwoWay;
                multiBinding.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);
            }
        }
        /// <summary>
        /// Creates a new localized value.
        /// </summary>
        /// <param name="targetObject"></param>
        /// <param name="targetProperty"></param>
        /// <param name="binding"></param>
        /// <param name="bindings"></param>
        /// <returns></returns>
        public static LocalizedValue Create(
            DependencyObjectProperty objectProperty,
            LocalizationOptions options
            )
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var localizedValue = new LocalizedValue(objectProperty.TargetObject, objectProperty.TargetProperty)
            {
                Key                = options.Key,
                StringFormat       = options.StringFormat,
                Callback           = options.Callback,
                CallbackParameter  = options.CallbackParameter,
                Converter          = options.Converter,
                ConverterParameter = options.ConverterParameter,
            };

            if (options.Binding != null || options.Bindings?.Count > 0)
            {
                if (false == (objectProperty.TargetProperty.PropertyObject is DependencyProperty))
                {
                    // The what bindings are implemented in WPF provides no way to obtain the value
                    // produced by the binging. The only way is to update the property directly. Therefore,
                    // the extension cannot support bindings on non-dependency properties (same as WPF).
                    throw new ArgumentException("Bindings are supported only on dependency properties.", nameof(options));
                }

                // Create a binding
                var localizedBinding = new MultiBinding()
                {
                    Mode = BindingMode.OneWay,
                };
                if (options.Binding != null)
                {
                    localizedBinding.Bindings.Add(options.Binding);
                }
                if (options.Bindings?.Count > 0)
                {
                    foreach (var item in options.Bindings)
                    {
                        localizedBinding.Bindings.Add(item);
                    }
                }

                localizedBinding.Converter       = localizedValue;
                localizedValue.BindingExpression = (BindingExpressionBase)localizedBinding.ProvideValue(objectProperty);
            }

            return(localizedValue);
        }
示例#15
0
        /// <summary>
        /// Return the value for this instance of the Markup Extension
        /// </summary>
        /// <param name="serviceProvider">The service provider</param>
        /// <returns>The value of the element</returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            object result = null;

            // register the target and property so we can update them
            //
            RegisterTarget(serviceProvider);

            // Show the icon in the notification tray to allow changing culture at design time
            //
            if (this.IsInDesignMode)
            {
                CultureManager.ShowCultureNotifyIcon();
            }

            if (string.IsNullOrEmpty(Key) && !IsBindingExpression)
            {
                throw new ArgumentException("You must set the resource Key or Binding properties");
            }

            // if the extension is used in a template or as a child of another
            // resx extension (for multi-binding) then return this
            //
            if (TargetProperty == null || IsMultiBindingChild)
            {
                result = this;
            }
            else
            {
                // if this extension has child Resx elements then invoke AFTER this method has returned
                // to setup the MultiBinding on the target element.
                //
                if (IsMultiBindingParent)
                {
                    MultiBinding binding = CreateMultiBinding();
                    result = binding.ProvideValue(serviceProvider);
                }
                else if (IsBindingExpression)
                {
                    // if this is a simple binding then return the binding
                    //
                    Binding binding = CreateBinding();
                    result = binding.ProvideValue(serviceProvider);
                }
                else
                {
                    // otherwise return the value from the resources
                    //
                    result = GetValue();
                }
            }
            return(result);
        }
示例#16
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var imageBinding = new Binding()
            {
                BindsDirectlyToSource = BindsDirectlyToSource,
                Mode  = BindingMode.OneWay,
                Path  = Path,
                XPath = XPath,
            };

            //Binding throws an InvalidOperationException if we try setting all three
            // of the following properties simultaneously: thus make sure we only set one
            if (ElementName != null)
            {
                imageBinding.ElementName = ElementName;
            }
            else if (RelativeSource != null)
            {
                imageBinding.RelativeSource = RelativeSource;
            }
            else if (Source != null)
            {
                imageBinding.Source = Source;
            }

            var targetElementBinding = new Binding();

            targetElementBinding.RelativeSource = new RelativeSource()
            {
                Mode = RelativeSourceMode.Self
            };

            var multiBinding = new MultiBinding();

            multiBinding.Bindings.Add(targetElementBinding);
            multiBinding.Bindings.Add(imageBinding);

            // If we set the Converter on resourceKeyBinding then, for some reason,
            // MultiBinding wants it to produce a value matching the Target Type of the MultiBinding
            // When it doesn't, it throws a wobbly and passes DependencyProperty.UnsetValue through
            // to our MultiBinding ValueConverter. To circumvent this, we do the value conversion ourselves.
            // See http://social.msdn.microsoft.com/forums/en-US/wpf/thread/af4a19b4-6617-4a25-9a61-ee47f4b67e3b
            multiBinding.Converter = new FileNameToImageSourceConverter()
            {
                ResourceKeyConverter = Converter,
                ConverterParameter   = ConverterParameter,
                StringFormat         = StringFormat,
                ResourceKeyFormat    = ResourceKeyFormat,
                CropRect             = CropRect
            };

            return(multiBinding.ProvideValue(serviceProvider));
        }
示例#17
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            MultiBinding multiBinding = new MultiBinding();

            multiBinding.Bindings.Add(Binding);
            multiBinding.Bindings.Add(ConverterParameterBinding);
            MultiValueConverterAdapter adapter = new MultiValueConverterAdapter();

            adapter.Converter      = Converter;
            multiBinding.Converter = adapter;
            return(multiBinding.ProvideValue(serviceProvider));
        }
示例#18
0
        /// <summary>
        /// このマークアップ拡張機能で使用するターゲット プロパティの値として提供されるオブジェクトを返します。
        /// </summary>
        /// <param name="serviceProvider">マークアップ拡張機能のサービスを提供できるサービス プロバイダー ヘルパー。</param>
        /// <returns>拡張機能が適用されたプロパティに設定するオブジェクトの値。</returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            MultiBinding mb = new MultiBinding()
            {
                Mode = BindingMode.OneWay
            };

            if (format is BindingBase)
            {
                // フォーマットがバインド可能な場合
                mb.Bindings.Add(format as BindingBase);
                mb.Converter = converter;
            }
            else
            {
#if false
                // リテラルの場合は、StringFormat にそのまま設定
                mb.StringFormat = format.ToString();
#else
                // StringFormat の機構を利用すると、
                // 例外が起きた時などの扱いがこのマークアップ拡張の動きと統一されないので
                // フォーマットがリテラルでも、StringFormatConverter を使う
                BindingBase binding = null;
                binding = new Binding()
                {
                    Source = format
                };
                mb.Bindings.Add(binding);
                mb.Converter = converter;
#endif
            }

            foreach (object arg in args)
            {
                BindingBase binding = null;
                if (arg is BindingBase)
                {
                    binding = (arg as BindingBase);
                }
                else
                {
                    binding = new Binding()
                    {
                        Source = arg
                    };
                }

                mb.Bindings.Add(binding);
            }

            return(mb.ProvideValue(serviceProvider));
        }
示例#19
0
            public object Execute()
            {
                // empty MultiBindings will fail at runtime
                // simply add an unused Binding, which won't be used in evaluation,
                // since there is no matching operation
                if (_bindings.Bindings.Count == 0)
                {
                    _bindings.Bindings.Add(new Binding {
                        Source = null
                    });
                }

                return(_bindings.ProvideValue(_serviceProvider));
            }
示例#20
0
        /// <summary>
        /// Represents the multibinding value of the service provider.
        /// </summary>
        /// <param name="serviceProvider">
        /// The service provider.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            MultiBinding multiBinding = new MultiBinding();

            multiBinding.Bindings.Add(
                new Binding {
                RelativeSource = new RelativeSource {
                    Mode = RelativeSourceMode.Self
                }
            });
            multiBinding.Bindings.Add(new Binding());
            multiBinding.Converter = new ResourceKeyToResourceConverter();
            return(multiBinding.ProvideValue(serviceProvider));
        }
        public override object ProvideValue(IServiceProvider rpServiceProvider)
        {
            var rResult = new MultiBinding()
            {
                Converter = CoreConverter.Instance
            };

            rResult.Bindings.Add(new Binding()
            {
                RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ListView), 1)
            });
            rResult.Bindings.Add(new Binding());

            return(rResult.ProvideValue(rpServiceProvider));
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var dynamicResource = new DynamicResourceExtension(this.ResourceKey);

            this.bindingSource = new BindingProxy(dynamicResource.ProvideValue(null));

            var dynamicResourceBinding = new Binding
            {
                Source = this.bindingSource,
                Path   = new PropertyPath(BindingProxy.ValueProperty),
                Mode   = BindingMode.OneWay
            };

            var targetInfo = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));

            if (targetInfo.TargetObject is DependencyObject dependencyObject)
            {
                dynamicResourceBinding.Converter          = this.Converter;
                dynamicResourceBinding.ConverterParameter = this.ConverterParameter;
                dynamicResourceBinding.ConverterCulture   = this.ConverterCulture;
                dynamicResourceBinding.StringFormat       = this.StringFormat;
                dynamicResourceBinding.TargetNullValue    = this.TargetNullValue;

                if (dependencyObject is FrameworkElement targetFrameworkElement)
                {
                    targetFrameworkElement.Resources.Add(this.bindingSource, this.bindingSource);
                }

                return(dynamicResourceBinding.ProvideValue(serviceProvider));
            }

            var findTargetBinding = new Binding {
                RelativeSource = new RelativeSource(RelativeSourceMode.Self)
            };

            this.bindingTrigger = new BindingTrigger();

            var wrapperBinding = new MultiBinding
            {
                Bindings =
                {
                    dynamicResourceBinding, findTargetBinding, this.bindingTrigger.Binding
                },
                Converter = new InlineMultiConverter(this.WrapperConvert)
            };

            return(wrapperBinding.ProvideValue(serviceProvider));
        }
示例#23
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var multiBinding = new MultiBinding();

            Binding.Mode = Mode;
            multiBinding.Bindings.Add(Binding);
            ConverterParameter.Mode = BindingMode.OneWay;
            multiBinding.Bindings.Add(ConverterParameter);
            var adapter = new MultiValueConverterAdapter
            {
                Converter = Converter
            };

            multiBinding.Converter = adapter;
            return(multiBinding.ProvideValue(serviceProvider));
        }
        public override object ProvideValue(IServiceProvider rpServiceProvider)
        {
            var rResult = new MultiBinding()
            {
                Mode = BindingMode.OneWay, Converter = Converter.Instance, ConverterParameter = r_Type, StringFormat = StringFormat
            };

            rResult.Bindings.Add(new Binding(r_IDPath));
            rResult.Bindings.Add(new Binding(r_OriginalTextPath));
            rResult.Bindings.Add(new Binding(nameof(StringResources.Instance.Extra))
            {
                Source = StringResources.Instance
            });

            return(rResult.ProvideValue(rpServiceProvider));
        }
示例#25
0
        public override object ProvideValue(IServiceProvider rpServiceProvider)
        {
            var rResult = new MultiBinding()
            {
                Mode = BindingMode.OneWay, Converter = CoreConverter.Instance
            };

            rResult.Bindings.Add(new Binding("ModifierKeys.Value")
            {
                Source = Preference.Instance.Other.PanicKey
            });
            rResult.Bindings.Add(new Binding("Key.Value")
            {
                Source = Preference.Instance.Other.PanicKey
            });

            return(rResult.ProvideValue(rpServiceProvider));
        }
示例#26
0
        /// <summary>
        /// Returns an object that should be set on the property where this binding and extension are applied.
        /// </summary>
        /// <param name="serviceProvider">The object that can provide services for the markup extension.  May be <see langword="null" />.</param>
        /// <returns>The value to set on the binding target property.</returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            DependencyObject target = null;

            if (serviceProvider != null)
            {
                var service = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;

                if (service != null)
                {
                    target = service.TargetObject as DependencyObject;

                    if (target != null && DesignerProperties.GetIsInDesignMode(target))
                    {
                        var property = service.TargetProperty as DependencyProperty;

                        return(property != null && property.PropertyType == typeof(System.Collections.IEnumerable)
              ? Binding.DoNothing
              : null);
                    }

                    @event = TryGetEventHandlerType(service.TargetProperty);
                }
            }

            if (@event != null)
            {
                return(ProvideEventHandler(target));
            }

            var expression = multiBinding.ProvideValue(serviceProvider) as MultiBindingExpression;

            if (expression == null)
            {
                // We could be inside of a template, in which case WPF expects a reference to the markup extension itself.
                return(this);
            }

            converter.Expression = expression;

            return(expression);
        }
        private object BindDictionary(IServiceProvider serviceProvider)
        {
            string define = _define ?? GetDefine(_target);
            string value  = _property.Name;

            Binding binding = new Binding("Dictionary")
            {
                Source = LanguageContext.Instance,
                Mode   = BindingMode.TwoWay
            };
            LanguageConverter converter = new LanguageConverter(define, value);

            if (_parameters.Count == 0)
            {
                binding.Converter = converter;
                object realvalue = binding.ProvideValue(serviceProvider);
                return(realvalue);
            }
            else
            {
                MultiBinding multiBinding = new MultiBinding
                {
                    Mode      = BindingMode.TwoWay,
                    Converter = converter
                };
                multiBinding.Bindings.Add(binding);
                if (string.IsNullOrEmpty(define))
                {
                    Binding defineBinding = _parameters[0] as Binding;
                    if (defineBinding == null)
                    {
                        throw new ArgumentException("Define Binding parameter must be the first, and of type Binding");
                    }
                }
                foreach (Binding parameter in _parameters)
                {
                    multiBinding.Bindings.Add(parameter);
                }
                object realvalue = multiBinding.ProvideValue(serviceProvider);
                return(realvalue);
            }
        }
        private object CreateMultiBinding(IServiceProvider serviceProvider)
        {
            var multiBinding = new MultiBinding
            {
                Converter = this
            };

            multiBinding.Bindings.Add(this.IconBinding);

            if (this.DesiredSizeBinding != null)
            {
                multiBinding.Bindings.Add(this.DesiredSizeBinding);
            }

            if (this.TargetVisualBinding != null)
            {
                multiBinding.Bindings.Add(this.TargetVisualBinding);
            }

            return(multiBinding.ProvideValue(serviceProvider));
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            IProvideValueTarget providerValueTarget = serviceProvider as IProvideValueTarget;
            MultiBinding        multiBinding        = new MultiBinding()
            {
                Converter             = new LocalizationConverter(Key),
                NotifyOnSourceUpdated = true
            };

            multiBinding.Bindings.Add(new Binding
            {
                Source = LocalizationManager.Current,
                Path   = new PropertyPath("CurrentCulture")
            });
            if (KeySource != null)
            {
                multiBinding.Bindings.Add(KeySource);
            }

            return(multiBinding.ProvideValue(serviceProvider));
        }
示例#30
0
        public override object ProvideValue(IServiceProvider rpServiceProvider)
        {
            if (!StringResources.Instance.IsLoaded)
            {
                return(Path);
            }


            var rResult = new MultiBinding()
            {
                Converter = r_Converter, ConverterParameter = Prefix, StringFormat = StringFormat, Mode = Mode, TargetNullValue = TargetNullValue
            };

            rResult.Bindings.Add(new Binding(Path));
            rResult.Bindings.Add(new Binding(nameof(StringResources.Instance.Main))
            {
                Source = StringResources.Instance
            });

            return(rResult.ProvideValue(rpServiceProvider));
        }