I have made an application with a Tree and a TreeView where the user can add and remove
nodes on the fly.
I am using three different icons in the tree to mark various things by using the ordinary way of creating a StackPanel (in code not in XAML).
As it is now I have to load these icons for each of the nodes I add from the file system which consumes a lot of resources and memory because I can not find a way of “reusing” the icons between the nodes in the tree.
I tried to create three default images at start but I could only use them for three nodes, the fourth node complain and said that the item (the image) was already in use.
I have seen on the internet some possibilities of creating a ImageList but those seems to be TreeViewitem related which mean that I have to create a new ImageList for each node?
Or can the same ImageList be reused between all nodes?
Sounds to me that you need to call
.Freeze()on your images.Although, I have a similar case in my app and this is how I have done it (without using
.Freeze()):XAML:
c# code:
Where I’m creating my nodes (as an example):