TreeView ItemTemplateSelector seems not working

Sep 23, 2013 at 11:21 AM

I'm using the TreeView control, and if I set the DataTemplate within the TreeView.Itemtemplate it works as it should be. However if I try to use an ItemTemplateSelector it doesn't work. I've set up debug point within my DataTemplateSelector implementation, and it not even reaches the debug point. Is the ItemTemplateSelector isn't implemented in the TreeView control?
Dec 14, 2013 at 9:07 PM
I have notice the same thing... in the scenario I am facing it would be very valuable to have ability to apply different ItemTemplate based on item, via Selector. Please consider adding this feature in upcoming release. Or let us know how to do it.
Dec 15, 2013 at 5:57 AM
I can take a look when I find some time, but I can't say when that will be. Meanwhile you can put a ContentControl in the items and that has a ContentTemplateSelector AFAIR.
Sep 18, 2014 at 1:05 PM
Apparently the problem still exists.
Sep 19, 2014 at 10:18 PM
I'm working on getting the TreeView to work on the phone. It's mostly done, but I have to clean the code up. I'll try to look into the template selector since I'm already looking at this code.
Sep 21, 2014 at 9:51 AM
Edited Sep 21, 2014 at 9:52 AM
I've tried the ContentControl solution and it seemed to work fine, but it has the limitation where the hierarchy always has to have the same property name for child nodes, so I got the template selector to work in the phone sample app and it should work on PC. I haven't tried but I think with this solution you should be able to have nodes with not only different templates but also different property names for child node lists. Let me know if that works for you.

Please note the control is not virtualized though and so it shouldn't be used for large lists. In that case I'd use a ListView with a template selector and a flat list of nodes where you would insert more nodes after tapping/expanding a parent node and remove these after tapping the parent node to collapse - similar to the way the sample app on Windows shows the groups of samples or as in my answer to this Stack Overflow question
Sep 22, 2014 at 11:29 AM
It seems to work now. Thanks for responding and fixing the issue so quickly. :)