This is a migrated thread and some comments may be shown as answers.

AutoBindBehavior with Value Converter

5 Answers 241 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
donovan
Top achievements
Rank 1
donovan asked on 11 May 2012, 08:15 PM
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.

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

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.

Thanks.

5 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 14 May 2012, 09:24 AM
Hi,

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.

Greetings,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Hrvoje Prgeša
Top achievements
Rank 1
answered on 21 Sep 2014, 11:45 AM
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"
                           VerticalContentAlignment="Stretch">
    <telerik:RadDropDownButton.Content>
        <Border telerik:AutoBindBehavior.UpdateBindingOnElementLoaded="Tag"
                    Background="{Binding Tag,
                                         RelativeSource={RelativeSource Self},
                                         Mode=OneWay,
                                         Converter={StaticResource DirectCanvasBrushToWpfBrushConverter}}" />
    </telerik:RadDropDownButton.Content>
    <telerik:RadDropDownButton.DropDownContent>
        <TextBlock />
    </telerik:RadDropDownButton.DropDownContent>
</telerik:RadDropDownButton>

Definitely too late for the original poster, but it might help someone in the future.
0
Yoan
Telerik team
answered on 23 Sep 2014, 02:17 PM
Hello,

Thank you for sharing your solution to the community.

Regards,
Yoan
Telerik
 
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.
 
0
Andréa
Top achievements
Rank 1
answered on 03 Jun 2020, 10:46 AM

Hello,

 

Updating old thread , any news about using IValueConverter with UpdateBindingOnElementLoaded ?

0
Martin Ivanov
Telerik team
answered on 08 Jun 2020, 08:27 AM

Hello Andréa,

This is still unsupported scenario.

Regards,
Martin Ivanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
PropertyGrid
Asked by
donovan
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Hrvoje Prgeša
Top achievements
Rank 1
Yoan
Telerik team
Andréa
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or