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

Adding nodes in code with custom sized image

2 Answers 55 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Anne Lyon
Top achievements
Rank 1
Anne Lyon asked on 06 Sep 2010, 01:40 PM
Hi,
I have a treeview where I add nodes dynamically in code (LoadOnDemand). This works fine, but I need to "label" the different nodes with different images depending on what kind of node it is. This also works fine - as long as the images are always 16x16 pixels. If they are not (sometimes I need images of 16x32) then the images are resized to 16px wide.
I tried to make a template to handle images of this size and created a ControlTemplate with an Image with Height and Width set. But when doing this I don't seem to be able to display the Text of the node (in the Header property). Adding a TextBlock to the template only displays an empty string. What is worse, the expand button disappears. So I think my solution is a dead end...

Now can anybody explain to me how to create a template (or other solution), that custom set the size of the image for a RadTreeViewItem but leaves the rest "as is" and that can be set/applied in code??

Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 09 Sep 2010, 12:04 PM
Hi Anne Lyon,

There are several approaches you can try:
1. Bind the width and height properties from data template to appropriate properties in your view model.
2. Use template selector to choose which template to be used for each item.
I'm attaching sample project demonstrating both solutions.

Hope this helps. Please let us know if you need more info.

Regards,
Hristo Milyakov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Anne Lyon
Top achievements
Rank 1
answered on 10 Sep 2010, 01:14 PM
Brilliant! Used the ViewModel solution and it works very well. Thanks!
Tags
TreeView
Asked by
Anne Lyon
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Anne Lyon
Top achievements
Rank 1
Share this question
or