Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I am using DataTemplateSelector in TreeViewControl and as it has a virtual method called "SelectTemplate".

SQL
public override DataTemplate SelectTemplate(object item, DependencyObject dependencyObject)
 {

}

As we all know that, SelectTemplate method will be called when we click on the tree view node. Now, again if we click on same node it does not execute SelectTemplate method as we all know.

But is there any option, property or any alternatives so that SelectTemplate method gets called everytime I click on any node or same node so that it calls SelectTemplate method.

Thanks in advance :)
Posted
Updated 23-Jun-11 20:21pm
v2
Comments
Mark Salsbery 23-Jun-11 16:55pm    
As we all know? SelectTemplate is called when a DataTemplate is needed. SelectTemplate has nothing to do with a click event, unless that click event is expanding a tree node and the system needs to select templates for the newly visible node(s). If you want to change templates when an event occurs then you'll need to implement that yourself.
Sanjay J Patolia 24-Jun-11 0:26am    
Yes , thats right but how to implement it explicitly?

1 solution

Why do you need to do it from code? There is an alternative which I describe here[^]. By doing this, you have one DataTemplate (which controls the conditions for switching the templates), and you change the other DataTemplates to ControlTemplates.
 
Share this answer
 
Comments
Sanjay J Patolia 24-Jun-11 2:37am    
I have tried so many ways, none of them worked out. Hope this will. I am trying with ur solution. Thank you :)
Pete O'Hanlon 24-Jun-11 3:15am    
No problem. As long as there's some form of trigger to bind to, this method works. It works so well that I no longer use manual DataTemplateSelectors.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900