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

Problem with EditorTemplateSelector

3 Answers 176 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Marcel
Top achievements
Rank 1
Iron
Marcel asked on 28 Oct 2014, 11:52 AM
Hi,

I can't figure out how to correctly use the EditorTemplateSelector with the RadPropertyGrid. I just want to apply custom DataTemplates for different types of properties. The applying parts works as expected but I don't understand how to get the DataContext to work. DataContext inside the DataTemplates is always pointing to the top level object that is bound to the RadPropertGrid as Item. It would really make more sense to me to have the specific property (or PropertyDefinition) as DataContext. So, how do I bind to the specific property from the Editor-DataTemplate?

Thanks for your help!

Marcel

3 Answers, 1 is accepted

Sort by
0
Accepted
Boris
Telerik team
answered on 30 Oct 2014, 03:47 PM
Hello Marcel,

A possible way for you to apply a DataTemplate depending only on the type of your property and not worry about the binding is to use our AutoBind Attached Behavior. For more information you can check the DataTemplateSelector Support article as well as our DataTemplateSelectors WPF / Silverlight demo and AutoBindAttachedBehavior sdk example. 

On a side note, to easily browse and run our sdk examples, you can use our SDK Sample Browser.

I attached a sample project that demonstrates the suggested approach.

I hope this helps.

Regards,
Boris Penev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Marcel
Top achievements
Rank 1
Iron
answered on 31 Oct 2014, 03:21 PM
Hi Boris,

thank you very much for your help. I think I forgot to mention that probably the cause of my problem were properties of complex objects from my object model. With the help of AutoBindBehavior.UpdateBindingOnElementLoaded together with your example I finally got it working. Still one thing is left that confuses me a little bit. Everything is fine if I do this:

<DataTemplate>
    <Grid>
        <StackPanel Orientation="Vertical">
            <TextBox telerik:AutoBindBehavior.UpdateBindingOnElementLoaded="DataContext" Text="{Binding Text}"/>
            <TextBox telerik:AutoBindBehavior.UpdateBindingOnElementLoaded="DataContext" Text="{Binding Text2}"/>
        </StackPanel>
    </Grid>
</DataTemplate>

But if I change it in a way the would be more conform to my understanding of WPF data binding, it does not work and throws binding errors:

<DataTemplate>
    <Grid telerik:AutoBindBehavior.UpdateBindingOnElementLoaded="DataContext">
        <StackPanel Orientation="Vertical">
            <TextBox Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}"/>
            <TextBox Text="{Binding Text2}"/>
        </StackPanel>
    </Grid>
</DataTemplate>

Looks like the DataContext is not inherited for whatever reason...

Regards,
Marcel
0
Boris
Telerik team
answered on 05 Nov 2014, 03:56 PM
Hi Marcel,

The way in which you use the AutoBindBehavior of the PropertyGrid seams unnatural. Since the AutoBindBehavior is meant to be bound to the main edit property of the editor and not to its DataContext. For example you can bind the AutoBindBehavior to the Text property of the TextBox editor. However, we haven't experimented with binding to the DataContext of the editor.

In order to provide you with a better answer on why the code from your first code-snippet works and the other does not, could you please provide us with a small runnable project? By providing us with such a project we will be able to debug it on our side and inform you of our findings. 

Regards,
Boris
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
PropertyGrid
Asked by
Marcel
Top achievements
Rank 1
Iron
Answers by
Boris
Telerik team
Marcel
Top achievements
Rank 1
Iron
Share this question
or