Beispiel #1
0
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     _bindableParam = new BindableParameter();
     //set the binding of the parameter
     BindingOperations.SetBinding(_bindableParam, BindableParameter.ParameterProperty, Binding);
     _bindableParam.TargetProperty = TargetProperty;
     return(_bindableParam);
 }
Beispiel #2
0
        /// <summary>
        /// Handles changes to the BindParameter property.
        /// </summary>
        private static void OnBindParameterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement element = d as FrameworkElement;

            if (element == null)
            {
                throw new InvalidOperationException("BindableParameter can be applied to a FrameworkElement only");
            }

            BindableParameter parameter = (BindableParameter)e.NewValue;

            element.Initialized += delegate
            {
                parameter.TargetExpression = BindingOperations.GetBindingExpression(element, parameter.TargetProperty);
                parameter.TargetBinding    = BindingOperations.GetBinding(element, parameter.TargetProperty);

                //update the converter parameter
                InvalidateBinding(parameter);
            };
        }
Beispiel #3
0
        private static void InvalidateBinding(BindableParameter param)
        {
            if (param.TargetBinding != null && param.TargetExpression != null)
            {
                //this is a hack to trick the WPF platform in thining that the binding is not sealed yet and then change the value of the converter parameter
                bool isSealed = (bool)isSealedFieldInfo.GetValue(param.TargetBinding);

                if (isSealed)    //change the is sealed value
                {
                    isSealedFieldInfo.SetValue(param.TargetBinding, false);
                }

                param.TargetBinding.ConverterParameter = param.ConverterParameterValue;

                if (isSealed)    //put the is sealed value back as it was...
                {
                    isSealedFieldInfo.SetValue(param.TargetBinding, true);
                }

                //force an update to the binding
                param.TargetExpression.UpdateTarget();
            }
        }
Beispiel #4
0
 /// <summary>
 /// Sets the BindParameter property.  This dependency property
 /// indicates ....
 /// </summary>
 public static void SetBindParameter(DependencyObject d, BindableParameter value)
 {
     d.SetValue(BindParameterProperty, value);
 }