public override object ProvideValue(IServiceProvider serviceProvider) { BindableParameter param = new BindableParameter(); //set the binding of the parameter //if (Binding == null && MultiBinding != null) // BindingOperations.SetBinding(param, BindableParameter.ParameterProperty, MultiBinding); //else if (Binding != null && MultiBinding == null) // BindingOperations.SetBinding(param, BindableParameter.ParameterProperty, Binding); if (Binding != null && Binding1 != null) { MultiBinding mb = new MultiBinding(); mb.Converter = MVConvert; mb.Bindings.Add(Binding); mb.Bindings.Add(Binding1); BindingOperations.SetBinding(param, BindableParameter.ParameterProperty, mb); } else if (Binding != null) { BindingOperations.SetBinding(param, BindableParameter.ParameterProperty, Binding); } param.TargetProperty = TargetProperty; return(param); }
/// <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; if (parameter != null) { element.Initialized += delegate { parameter.TargetExpression = BindingOperations.GetBindingExpression(element, parameter.TargetProperty); parameter.TargetBinding = BindingOperations.GetBinding(element, parameter.TargetProperty); //update the converter parameter InvalidateBinding(parameter); }; } }
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(); } }
/// <summary> /// Sets the BindParameter property. This dependency property /// indicates .... /// </summary> public static void SetBindParameter(DependencyObject d, BindableParameter value) { d.SetValue(BindParameterProperty, value); }