Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Display different icons to different nodes

Display different icons to different nodes

Scheduled Pinned Locked Moved WPF
questioncomtutorial
6 Posts 2 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jdkulkarni
    wrote on last edited by
    #1

    How can I show different icons/images to different nodes in a TreeListView? I am referring the example http://blogs.msdn.com/atc_avalon_team/attachment/541206.ashx[^] I want to show one image to all root nodes and another to all child nodes.

    Jayant D. Kulkarni

    L 1 Reply Last reply
    0
    • J jdkulkarni

      How can I show different icons/images to different nodes in a TreeListView? I am referring the example http://blogs.msdn.com/atc_avalon_team/attachment/541206.ashx[^] I want to show one image to all root nodes and another to all child nodes.

      Jayant D. Kulkarni

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Look into WPF DataTemplates. You can use a TemplateSelector to select different templates based on some code in the TemplateSelector or you can use a DataTrigger in the DataTemplate to change which icon is displayed.

      Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

      Just a grain of sand on the worlds beaches.

      J 1 Reply Last reply
      0
      • L Lost User

        Look into WPF DataTemplates. You can use a TemplateSelector to select different templates based on some code in the TemplateSelector or you can use a DataTrigger in the DataTemplate to change which icon is displayed.

        Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

        Just a grain of sand on the worlds beaches.

        J Offline
        J Offline
        jdkulkarni
        wrote on last edited by
        #3

        Thanks Karl. It worked for me. One more question, can we have separate icon for each node? I am asking because currently I am assigning image depending upon the HasItem property of treenode. In future I will like to show different icons for each node. Is it possible?

        Jayant D. Kulkarni Brainbench Certified Software Engineer in C#1.1, C# 2.0, ASP.NET, .NET Framework and ADO.NET

        L 1 Reply Last reply
        0
        • J jdkulkarni

          Thanks Karl. It worked for me. One more question, can we have separate icon for each node? I am asking because currently I am assigning image depending upon the HasItem property of treenode. In future I will like to show different icons for each node. Is it possible?

          Jayant D. Kulkarni Brainbench Certified Software Engineer in C#1.1, C# 2.0, ASP.NET, .NET Framework and ADO.NET

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yep. :cool: Use one of the two previous methods I gave you and test against the data that is bound to the TreeV Item. Then display the icon you want. WPF makes things like this very simple for developers. Got to love WPF. :rose:

          Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

          Just a grain of sand on the worlds beaches.

          J 1 Reply Last reply
          0
          • L Lost User

            Yep. :cool: Use one of the two previous methods I gave you and test against the data that is bound to the TreeV Item. Then display the icon you want. WPF makes things like this very simple for developers. Got to love WPF. :rose:

            Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

            Just a grain of sand on the worlds beaches.

            J Offline
            J Offline
            jdkulkarni
            wrote on last edited by
            #5

            Thanks Karl for reply. Yes it can be done using different properties, for example check the tag value and set the image. Now I am crating a generic user control and I want these images should dynamically get assigned. So, application1 will like some another icon at root level and different icon at child node level, similarly application2 will like to use some different icons. What I will like to do is let the application using my control set the images programmatically. How can we do this?

            Jayant D. Kulkarni Brainbench Certified Software Engineer in C#1.1, C# 2.0, ASP.NET, .NET Framework and ADO.NET

            L 1 Reply Last reply
            0
            • J jdkulkarni

              Thanks Karl for reply. Yes it can be done using different properties, for example check the tag value and set the image. Now I am crating a generic user control and I want these images should dynamically get assigned. So, application1 will like some another icon at root level and different icon at child node level, similarly application2 will like to use some different icons. What I will like to do is let the application using my control set the images programmatically. How can we do this?

              Jayant D. Kulkarni Brainbench Certified Software Engineer in C#1.1, C# 2.0, ASP.NET, .NET Framework and ADO.NET

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              This a SUPER easy in WPF. Read up on Styles and ControlTemplates. There are a lot of WPF articles here on Code Project that cover this topic. This is one of the foundational powers that WPF delivers. You can simply write one Style, place it in application scope and all Tree controls can use it. The possibilities are endless.

              Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

              Just a grain of sand on the worlds beaches.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups