none
Feature lag: Binding ConverterParameter

    Question

  • Just a little note:
    It may be a little seldom. But I am in a situation where I wanted to bind the ConverterParameter to an elements ActualHeight.

    But ConvertParameter dosn't seem to be a DependencyProperty.

    System.Windows.Markup.XamlParseException: A 'Binding' cannot be set on the 'ConverterParameter' property of type 'Binding'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

    Best regards,
      Thomas Andersen

    Tuesday, September 12, 2006 11:59 AM

Answers

  • Hi Thomas,

    That's correct. In fact, Binding is not even a DependencyObject, so its properties can not be DependencyProperties. This was a conscious decision and we are not planning to change it. We made this decision after brainstorming for a while about many of the infinite recursions and other bad invalid scenarios that this would open up.

    Let me see if I understand the behavior you are trying to achieve. You want your binding to be re-evaluated when its source changes or when the source of the Binding in the ConverterParameter changes, right? Then you want to produce a value for the target that is based on both of those sources. If this is the case, you can get this same behavior with a multibinding. Add two bindings to the multibinding: one of them is your initial Binding, without the ConverteParameter; the other one is the Binding that you wanted to set in the ConverterParameter. Both of those will be passed as a parameter to a MultiBinding Converter, and you can use them to base your decision of the target value. My last blog post shows how to do a MultiBinding.

    Let me know if this helps.

    Bea

    Tuesday, September 12, 2006 4:37 PM
    Moderator

All replies

  • Hi Thomas,

    That's correct. In fact, Binding is not even a DependencyObject, so its properties can not be DependencyProperties. This was a conscious decision and we are not planning to change it. We made this decision after brainstorming for a while about many of the infinite recursions and other bad invalid scenarios that this would open up.

    Let me see if I understand the behavior you are trying to achieve. You want your binding to be re-evaluated when its source changes or when the source of the Binding in the ConverterParameter changes, right? Then you want to produce a value for the target that is based on both of those sources. If this is the case, you can get this same behavior with a multibinding. Add two bindings to the multibinding: one of them is your initial Binding, without the ConverteParameter; the other one is the Binding that you wanted to set in the ConverterParameter. Both of those will be passed as a parameter to a MultiBinding Converter, and you can use them to base your decision of the target value. My last blog post shows how to do a MultiBinding.

    Let me know if this helps.

    Bea

    Tuesday, September 12, 2006 4:37 PM
    Moderator
  • Hi Bea,

    You are absolutely right. Multi binding would solve the problem, using the ConverterPatameter was just a workaround.
    Actually I solved my problem with a bit of logical thinking instead: I was using a StackPanel so changing it to a Grid solved my resizing problems.

    Thanks (and I have added your blog to my Live page)
    Best regards,
      Thomas Andersen

     

    Wednesday, September 13, 2006 7:12 AM