Exemple #1
0
        private static void OnMultiBindingChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
        {
            Setter setter = d as Setter;

            if (setter == null || setter.Property == null || args.OldValue != null)
            {
                throw new InvalidOperationException("Can only apply Multibinding attached property on a Setter where the Property has been set before and no value has previosly been assigned to the Multibinding property.");
            }
            if (args.NewValue != null)
            {
                if (DesignerProperties.IsInDesignTool)
                {
                    return;
                }

                MultiBinding mb = (MultiBinding)args.NewValue;
                mb.ApplyToStyle(setter);
                setter.Value = mb;
            }
        }
Exemple #2
0
        private static void OnDependencyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
        {
            MultiBinding mb = (MultiBinding)d;

            mb.CheckSealed();
        }
Exemple #3
0
 public static void SetStyleBinding(DependencyObject obj, MultiBinding value)
 {
     obj.SetValue(StyleBindingProperty, value);
 }
        /// <summary>
        /// Applies this <see cref="MultiBindingExpression"/> to the target
        /// </summary>
        /// <returns></returns>
        private void ApplyToTarget()
        {
            int dataPropertyIndex; // Next data property index to use

            // Get any existing MultiBindingInfo for this target
            List <MultiBindingExpression> mbExpressions = GetMultiBindingExpressions(Target);

            if (mbExpressions == null) // if no existing MultiBindings on this target
            {
                mbExpressions = new List <MultiBindingExpression>(1);

                dataPropertyIndex = 0;
            }
            else
            {
                // Fetch last used data property index from last expression.
                dataPropertyIndex = mbExpressions[mbExpressions.Count - 1].m_lastIndex + 1;
            }

            // Fill in this expression with information about this binding and all sources, converters and bindings.
            // and set attached data properties on the target as required.
            m_sourceStartIndex = dataPropertyIndex;

            foreach (DependencyProperty sourceProperty in MultiBinding.SourceProperties)
            {
                object localValue = MultiBinding.ReadLocalValue(sourceProperty);
                if (localValue == DependencyProperty.UnsetValue)
                {
                    break;
                }

                SetDataProperty(dataPropertyIndex++, localValue);
            }
            if (MultiBinding.Bindings != null && MultiBinding.Bindings.Count > 0)
            {
                if (dataPropertyIndex != m_sourceStartIndex)
                {
                    throw new InvalidOperationException("MutliBinding.Bindings cannot be used at the same time as Source-properties.");
                }
                for (int i = 0; i < MultiBinding.Bindings.Count; i++)
                {
                    SetDataProperty(dataPropertyIndex++, MultiBinding.Bindings[i]);
                }
            }
            m_sourceCount = dataPropertyIndex - m_sourceStartIndex;

            object converter = MultiBinding.ReadLocalValue(MultiBinding.ConverterProperty);

            if (converter is BindingExpression)
            {
                m_converterIndex = dataPropertyIndex++;
                SetDataProperty(m_converterIndex, converter);
            }

            object converterParameter = MultiBinding.ReadLocalValue(MultiBinding.ConverterParameterProperty);

            if (converterParameter is BindingExpression)
            {
                m_converterParameterIndex = dataPropertyIndex++;
                SetDataProperty(m_converterParameterIndex, converterParameter);
            }

            object stringFormat = MultiBinding.ReadLocalValue(MultiBinding.StringFormatProperty);

            if (stringFormat is BindingExpression)
            {
                m_stringFormatIndex = dataPropertyIndex++;
                SetDataProperty(m_stringFormatIndex, stringFormat);
            }

            m_lastIndex = dataPropertyIndex - 1;

            // Update MultiBindingInfoProperties for target
            mbExpressions.Add(this);
            if (mbExpressions.Count == 1)
            {
                Target.SetValue(MultiBindingExpressionsProperty, mbExpressions);
            }
            // Queue up an update request to ensure that the SourceValues property will be set.
            //BeginUpdate();
        }