Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6724439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:41:24+00:00 2026-05-26T09:41:24+00:00

I have made an application with a Tree and a TreeView where the user

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:41:25+00:00Added an answer on May 26, 2026 at 9:41 am

    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:

        <TreeView Name="treeViewFolders" SelectedItemChanged="treeViewFolders_SelectedItemChanged" TreeViewItem.Expanded="treeViewFolders_Expanded" Margin="0,4,0,6">
            <TreeView.Resources>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="HeaderTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" Margin="0,2">
                                    <Image x:Name="img" Stretch="None" RenderOptions.BitmapScalingMode="NearestNeighbor" 
                                           Source="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TreeViewItem}, Path=DataContext}"/>
                                    <TextBlock Text="{Binding}" Margin="5,0,10,0" />
                                </StackPanel>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </TreeView.Resources>
        </TreeView>
    

    c# code:

    private readonly System.Collections.Generic.Dictionary<string, ImageSource> typeIcons = new Dictionary<string, ImageSource>();
    
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
            this.typeIcons.Add("winhdd", new BitmapImage(new Uri("Images/Icons/winhdd.png", UriKind.Relative)));
            this.typeIcons.Add("harddrive", new BitmapImage(new Uri("Images/Icons/hdd.png", UriKind.Relative)));
            this.typeIcons.Add("removable", new BitmapImage(new Uri("Images/Icons/removablehdd.png", UriKind.Relative)));
            this.typeIcons.Add("folder", new BitmapImage(new Uri("Images/Icons/folder.png", UriKind.Relative)));
    }
    

    Where I’m creating my nodes (as an example):

    TreeViewItem item = new TreeViewItem();
    item.DataContext = this.typeIcons["harddrive"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made an application (for my self) for feeds reading, using SyndicationFeed ,
I have made an application using Java/Hibernate/MySQL, but whenever I try running it, it
I have made an application that gives the user the option to open up
I have made an application that can render and save a given element. With
I have made a application that can copy files to places in two TreeViews
I have made an application using Ruby. Some gems are being used in it(approx.
I have made an application which draws a number of curves, using UIBezierPath. Now
I have made an application and I have installed it on my iphone, but
I have made a swings application but there is one problem in that which
I have made a java application and have packed it into an executable jar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.