AutoBindBehavior with Value Converter

4 posts, 0 answers
  1. donovan
    donovan avatar
    13 posts
    Member since:
    Oct 2011

    Posted 11 May 2012 Link to this post

    I have a couple Boolean properties on my object that by default are being rendered as Check Boxes.  I have put a Data Template Selector class in place to provide a new template that uses a simple TextBlock.  The problem is instead of the TextBlock showing True or False (which it does by default) I want it to show Yes or No.  So I also created a simple class that implements IValueConverter to change Booleans to Yes or No.  Because I have multiple similar properties I want to reuse the same data template.

          <TextBlock telerik:AutoBindBehavior.UpdateBindingOnElementLoaded="Text" Text="{Binding Converter={StaticResource YesNo}}" />

    I thought using the AutoBindBehavior would do the trick (and it might I could be using it wrong) but when my value converter is called I am passed the Parent object and not just the value of the property being rendered. 
    I have a feeling my Binding expression for my Text property on the data template is wrong but I am unable to figure out the proper value.

  2. Ivan Ivanov
    Ivan Ivanov avatar
    1201 posts

    Posted 14 May 2012 Link to this post


    Currently the AutoBind attached behavior does not support IValueConverter, but we have planned to implement such a feature for some version in the close future. A possible approach would be to introduce a new property to your business object that would carry out the conversion instead. As a side note please let me shed some more light on this attached behavior's internal mechanics. When the underlying data template is loaded, the editor control has the property, which is passed as behavior's parameter ("Text" in our example), bound by using the binding path specified by its respective PropertyDefinition. So that this binding won't be respected, as it would be overriden at a later point of your application's lifecycle:
    Text="{Binding Converter={StaticResource YesNo}}"
    Here is a help article that illustrates this in practice. Please, let us know whether the proposed approach would be a viable one in your case and do not hesitate to contact us if any further assistance is needed.

    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. Hrvoje Prgeša
    Hrvoje Prgeša avatar
    1 posts
    Member since:
    Jul 2012

    Posted 21 Sep 2014 in reply to Ivan Ivanov Link to this post

    Reviving an old thread since it the first google hit for "UpdateBindingOnElementLoaded converter":

    Binding through Tag works for us - you set the element Tag through UpdateBindingOnElementLoaded  and than bind to Tag using the converter.

    <telerik:RadDropDownButton HorizontalContentAlignment="Stretch"
            <Border telerik:AutoBindBehavior.UpdateBindingOnElementLoaded="Tag"
                        Background="{Binding Tag,
                                             RelativeSource={RelativeSource Self},
                                             Converter={StaticResource DirectCanvasBrushToWpfBrushConverter}}" />
            <TextBlock />

    Definitely too late for the original poster, but it might help someone in the future.
  4. Yoan
    Yoan avatar
    1128 posts

    Posted 23 Sep 2014 Link to this post


    Thank you for sharing your solution to the community.

    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
Back to Top