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

How to force ItemTemplateSelector to rebind templates.

3 Answers 120 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Miłosz Cechnicki
Top achievements
Rank 1
Miłosz Cechnicki asked on 15 Oct 2009, 09:48 AM
Hi,
I'm developing an treeview. I'm using an ItemTemplateSelector object to apply different styles depending on items' properties, mainly the IsNodeValid property. Same object can be inserted in many places in a single tree.
And what i want to achive, is to force the tree view to rebind templates to all of the items after change of the IsNodeValid property of any item (it will be also ok to rebind the style only for the items, that reference updated object).

Is there any possibility to this? I've tried rebinding the ItemTemplateSelector property (setting it to null, and then once againt to the object taken from resources) - but no success. Also calling the ApplyTemplate method on the tree doesn't success.

3 Answers, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 16 Oct 2009, 02:09 PM
Hi Miłosz,

Unfortunately the templates selected form the ItemTemplateSelector cannot be rebound.

I can suggest two things in your case:

1. Use container bindings and bind a property of the container (the TreeViewItem) to your ViewModel. You need to make sure that your property (IsNodeValid) is observable, then you can use the ContainerBindings attached proeprty to attach container bindings to the templates selected by the selector. (I can help you with more information on that if you need)

2. If this property is some kind of validation and you want the outlook of the template to change, you can bind to this property using a converter. For example you can implement a BooleanToBrush converter and bind the Background of an element in the template to this property.

If you need more drastic changes in the template, you can use a BooleanToVisibility converter and bind the visibility of an object to this property. This way when it is set you will be able to significantly change the look of your template without replacing it.

Hopefully this will work in your case,

Sincerely yours,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Miłosz Cechnicki
Top achievements
Rank 1
answered on 19 Oct 2009, 09:27 AM
Hi Miroslav,
thank you for Your response.
I've found an example on using this functionality. Do You plan to implement such a functionality in future releases?
As I see, it is possible to rebind this by removing and inserting item to the tree. But these causes the tree to slide and move for a while.
It would be great to rebind all templates on, for example, changing the selected template from code.

Best regards
0
Miroslav
Telerik team
answered on 20 Oct 2009, 07:51 AM
Hello Miłosz Cechnicki,

You say that

"I've found an example on using this functionality"

Do you refer to an example about refreshing the ItemTemplates? Could you please post a link to this example?

In general we do not plan to introduce this functionality for the Q3 release. One reason for this is that we are not notifies by the base items control when the ItemTemplate property changes.

I have added your suggestion to the product backlog.

All the best,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
Miłosz Cechnicki
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Miłosz Cechnicki
Top achievements
Rank 1
Share this question
or