当前位置: 首页>>代码示例>>C#>>正文


C# MultiBinding.ProvideValue方法代码示例

本文整理汇总了C#中System.Windows.Data.MultiBinding.ProvideValue方法的典型用法代码示例。如果您正苦于以下问题:C# MultiBinding.ProvideValue方法的具体用法?C# MultiBinding.ProvideValue怎么用?C# MultiBinding.ProvideValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Data.MultiBinding的用法示例。


在下文中一共展示了MultiBinding.ProvideValue方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProvideValue

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (this.Key == null && this.KeyBinding == null)
                throw new ArgumentException("Either Key or KeyBinding must be set");
            if (this.Key != null && this.KeyBinding != null)
                throw new ArgumentException("Either Key or KeyBinding must be set, but not both");
            if (this.ValueBinding != null && this.ValueBindings != null)
                throw new ArgumentException("ValueBinding and ValueBindings may not be set at the same time");

            // Most of these conditions are redundent, according to the assertions above. However I'll still state them,
            // for clarity.

            // A static key, and no values
            if (this.Key != null && this.KeyBinding == null && this.ValueBinding == null && this.ValueBindings == null)
            {
                // Just returning a string!
                return Localizer.Translate(this.Key);
            }
            // A static key, and a single value
            if (this.Key != null && this.KeyBinding == null && this.ValueBinding != null && this.ValueBindings == null)
            {
                var converter = new StaticKeySingleValueConverter() { Key = this.Key, Converter = this.ValueBinding.Converter };
                this.ValueBinding.Converter = converter;
                return this.ValueBinding.ProvideValue(serviceProvider);
            }
            // A static key, and multiple values
            if (this.Key != null && this.KeyBinding == null && this.ValueBinding == null && this.ValueBindings != null)
            {
                var converter = new StaticKeyMultipleValuesConverter() { Key = this.Key, Converter = this.ValueBindings.Converter };
                this.ValueBindings.Converter = converter;
                return this.ValueBindings.ProvideValue(serviceProvider);
            }
            // A bound key, no values
            if (this.Key == null && this.KeyBinding != null && this.ValueBinding == null && this.ValueBindings == null)
            {
                var converter = new BoundKeyNoValuesConverter() { Converter = this.KeyBinding.Converter };
                this.KeyBinding.Converter = converter;
                return this.KeyBinding.ProvideValue(serviceProvider);
            }
            // A bound key, and one value
            if (this.Key == null && this.KeyBinding != null && this.ValueBinding != null && this.ValueBindings == null)
            {
                var converter = new BoundKeyWithValuesConverter();
                var multiBinding = new MultiBinding() { Converter = converter };
                multiBinding.Bindings.Add(this.KeyBinding);
                multiBinding.Bindings.Add(this.ValueBinding);
                return multiBinding.ProvideValue(serviceProvider);
            }
            // A bound key, and multiple values
            if (this.Key == null && this.KeyBinding != null && this.ValueBinding == null && this.ValueBindings != null)
            {
                var converter = new BoundKeyWithValuesConverter() { ValuesConverter = this.ValueBindings.Converter };
                this.ValueBindings.Bindings.Insert(0, this.KeyBinding);
                this.ValueBindings.Converter = converter;
                return this.ValueBindings.ProvideValue(serviceProvider);
            }

            throw new Exception("Should never get here");
        }
开发者ID:johnhk,项目名称:SyncTrayzor,代码行数:59,代码来源:LocExtension.cs

示例2: ProvideValue

        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);
        }
开发者ID:amatukaze,项目名称:IntelligentNavalGun,代码行数:8,代码来源:ItemIndexExtension.cs

示例3: ProvideValue

        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);
        }
开发者ID:amatukaze,项目名称:IntelligentNavalGun,代码行数:8,代码来源:PanicKeyPreferenceExtension.cs

示例4: ProvideValue

        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);
        }
开发者ID:amatukaze,项目名称:IntelligentNavalGun-Fx4,代码行数:9,代码来源:ExtraStringResourceExtension.cs

示例5: ProvideValue

        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);
        }
开发者ID:amatukaze,项目名称:IntelligentNavalGun,代码行数:12,代码来源:EnumToStringResourceExtension.cs

示例6: ProvideValue

        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("Layout.LandscapeDock") { Source = Preference.Current });
            rResult.Bindings.Add(new Binding("Layout.PortraitDock") { Source = Preference.Current });
            rResult.Bindings.Add(new Binding() { RelativeSource = RelativeSource.Self });

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

            return rResult.ProvideValue(rpServiceProvider);
        }
开发者ID:amatukaze,项目名称:IntelligentNavalGun-Fx4,代码行数:13,代码来源:CurrentDockExtension.cs

示例7: ProvideValue

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var resourceKeyBinding = 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)
            {
                resourceKeyBinding.ElementName = ElementName;
            }
            else if (RelativeSource != null)
            {
                resourceKeyBinding.RelativeSource = RelativeSource;
            }
            else if (Source != null)
            {
                resourceKeyBinding.Source = Source;
            }

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

            var multiBinding = new MultiBinding();
            multiBinding.Bindings.Add(targetElementBinding);
            multiBinding.Bindings.Add(resourceKeyBinding);

            // 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 ResourceKeyToResourceConverter()
            {
                ResourceKeyConverter = Converter,
                ConverterParameter = ConverterParameter,
                StringFormat = StringFormat,
            };

            return multiBinding.ProvideValue(serviceProvider);
        }
开发者ID:BDDCloud,项目名称:Amazon.OrderFulfillment,代码行数:49,代码来源:ResourceKeyBindingExtension.cs

示例8: ProvideValue

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (MultiBinding != null)
            {
                if (Bindings.Any())
                    throw new ArgumentException($"{nameof(Bindings)} should be an empty");
                if (Converter != null)
                    throw new ArgumentException($"{nameof(Converter)} should be a null");
            }
            else
            {
                if (!Bindings.Any())
                    throw new ArgumentNullException(nameof(Bindings));
                if (Converter == null)
                    throw new ArgumentNullException(nameof(Converter));
            }

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

            if (MultiBinding != null)
            {
                Converter = MultiBinding.Converter;
                ConverterParameter = MultiBinding.ConverterParameter;
                ConverterCulture = MultiBinding.ConverterCulture;
                foreach (var bindingBase in MultiBinding.Bindings)
                    Bindings.Add(bindingBase);
            }

            if (target.TargetObject is NestedBindingCollection)
            {
                var binding = new Binding
                {
                    Source = this
                };
                return binding;
            }

            var multiBinding = new MultiBinding
            {
                Mode = BindingMode.OneWay
            };
            var tree = GetNestedBindingsTree(this, multiBinding);
            var converter = new NestedBindingConverter(tree);
            multiBinding.Converter = converter;

            return multiBinding.ProvideValue(serviceProvider);
        }
开发者ID:itabaev,项目名称:wpf-nestedbinding,代码行数:49,代码来源:NestedBinding.cs

示例9: ProvideValue

        public override object ProvideValue(IServiceProvider rpServiceProvider)
        {
            var rSource = Preference.Instance.UI.HeavyDamageLine;
            var rResult = new MultiBinding()
            {
                Mode = BindingMode.OneWay,
                Converter = CoreConverter.Instance,
                Bindings = { new Binding(nameof(rSource.Type.Value)) { Source = rSource.Type } },
            };

            if (!r_State.HasValue)
                rResult.Bindings.Add(new Binding("State"));
            else
                rResult.ConverterParameter = r_State.Value;

            return rResult.ProvideValue(rpServiceProvider);
        }
开发者ID:amatukaze,项目名称:IntelligentNavalGun,代码行数:17,代码来源:HeavyDamageLineColorExtension.cs

示例10: ProvideValue

        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;
        }
开发者ID:itabaev,项目名称:wpflocalization,代码行数:74,代码来源:LocalizationExtension.cs

示例11: ProvideValue

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            DebugHelper.AssertUIThread();

            object value = null;

            Binding binding = new Binding("Value");
            BinaryMetadataConverter instanceConverter = new BinaryMetadataConverter(this.structType, this.path, this.converter, this.converterParameter);

            MultiBinding multiBinding = new MultiBinding()
                {
                    Converter = instanceConverter,
                    Mode = this.BindingMode,
                };
            multiBinding.Bindings.Add(binding);

            value = multiBinding.ProvideValue(serviceProvider);

            return value;
        }
开发者ID:UnaNancyOwen,项目名称:Kinect-Studio-Sample,代码行数:20,代码来源:BinaryMetadataBinding.cs

示例12: GetLocalizedValue

        /// <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);
        }
开发者ID:SeptemberWind,项目名称:ProductManager-WPF,代码行数:62,代码来源:BindingLocalizedValue.cs

示例13: bindDictionary

        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;
            }
        }
开发者ID:jstorm1,项目名称:winpure-contact-management,代码行数:33,代码来源:TranslateExtension.cs

示例14: GetLocalizedValue

		/// <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);
		}
开发者ID:Wdovin,项目名称:vc-community,代码行数:58,代码来源:MultiBindingLocalizedValue.cs


注:本文中的System.Windows.Data.MultiBinding.ProvideValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。