locked
Databinding ConverterParameter RRS feed

  • Question

  • I Have a custom UserControl ( Derives from IndicatorBase wich derives from UserControl ). IndicatorBase has a DependancyProperty Format.

    In my usercontrol I want to bind a object to the Text Property of an TextBlock. I want to convert this object to text using my own custom FormattingConverter. This converter takes a string parameter wich it uses to format the object.

    In the XAML Ihave this set as the Text Property "{Binding ElementName=myControl, Path=Value, Converter={StaticResource formatter}, ConverterParameter={???}}"

    What do Ineed to set at the ???. When I Try to bind the Format property to ConverterParameter I get the message that it is not an dependency property and I can't bind to it.

    How can I use my Format Property to format the text in the TextBlock?
    Monday, December 3, 2007 1:39 PM

Answers

  • As you have realised, you can only Bind to a dependency property, and ConverterParemeter isnt one.

     

    Why not add another dependecy property called "FormattedText" to your UserControl that does the conversion for you, without needing a Converter. Update it in the setters for Value and Format. You can then bind directly to that. 

     

    HTH,

    Nick.

    Monday, December 3, 2007 3:16 PM

All replies

  • As you have realised, you can only Bind to a dependency property, and ConverterParemeter isnt one.

     

    Why not add another dependecy property called "FormattedText" to your UserControl that does the conversion for you, without needing a Converter. Update it in the setters for Value and Format. You can then bind directly to that. 

     

    HTH,

    Nick.

    Monday, December 3, 2007 3:16 PM
  • Yes I think I will do it that way. I thought there might be a way without introducing an extra property.
    Wednesday, December 5, 2007 11:35 AM