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. Silverlight Hierarchical template for Multiple Types in Treeview

Silverlight Hierarchical template for Multiple Types in Treeview

Scheduled Pinned Locked Moved WPF
docker
2 Posts 2 Posters 0 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.
  • W Offline
    W Offline
    www Developerof NET
    wrote on last edited by
    #1

    public class TreeItem { public string HeaderTag { get; set; } public List<TreeStatusItem> StatusItems { get; set; } public List<TreeItem> items { get; set; } public TreeItem() { StatusItems = new List<TreeStatusItem>(); } } public class TreeStatusItem { #region Properties [DataMember] public string StatusText { get; set; } [DataMember] public string StatusValue { get; set; } } Here a TreeItem has a HaderTag which displays as the Header for the treeview, the StatusItems contains items of a different type and the items have a List of the container class itself. The sample data would be -RegionName(object of TreeItem type) --Oustanding(object of TreeStatusItem type) --Live (object of TreeStatusItem type) --Areas(object of TreeItem type) ----Oustanding(object of TreeStatusItem type) ----Live (object of TreeStatusItem type) ----SubAreas(object of TreeItem type) ...... ... I need to bind the data which is List<TreeItem> to a silverlight treeview. I can`t figure out how the hierarchical template should be !!!!

    When you fail to plan, you are planning to fail.

    M 1 Reply Last reply
    0
    • W www Developerof NET

      public class TreeItem { public string HeaderTag { get; set; } public List<TreeStatusItem> StatusItems { get; set; } public List<TreeItem> items { get; set; } public TreeItem() { StatusItems = new List<TreeStatusItem>(); } } public class TreeStatusItem { #region Properties [DataMember] public string StatusText { get; set; } [DataMember] public string StatusValue { get; set; } } Here a TreeItem has a HaderTag which displays as the Header for the treeview, the StatusItems contains items of a different type and the items have a List of the container class itself. The sample data would be -RegionName(object of TreeItem type) --Oustanding(object of TreeStatusItem type) --Live (object of TreeStatusItem type) --Areas(object of TreeItem type) ----Oustanding(object of TreeStatusItem type) ----Live (object of TreeStatusItem type) ----SubAreas(object of TreeItem type) ...... ... I need to bind the data which is List<TreeItem> to a silverlight treeview. I can`t figure out how the hierarchical template should be !!!!

      When you fail to plan, you are planning to fail.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      I create a class ReportNode, it uses the NodeTag property to store the actual record that is used to populate the treenode

      	public class ReportNode : ViewModelBase
      	{
      		public ReportNode(string sLabel, object oObject, string sColor)
      		{
      			NodeLabel = sLabel;
      			NodeTag = oObject;
      			Color = sColor;
      		}
      		public string NodeLabel { get; set; }
      		public object NodeTag { get; set; }
      		public string Color { get; set; }
      
      		private ObservableCollection<ReportNode> \_ChildNodes;
      		public ObservableCollection<ReportNode> ChildNodes
      		{
      			get
      			{ return \_ChildNodes; }
      			set
      			{
      				\_ChildNodes = value;
      				base.OnPropertyChanged("ChildNodes");
      			}
      		}
      	}
      

      Hierarchical data template binds the itemssource to the ChildNodes collection. When loading the nodes I stuff the NodeLabel with the text to display and the list object goes in the NodeTag property. When accessing the node I test the typeof the nodetag to determine what to do with the node. I have 1 tree with 6 different data sources, works perfectly.

      Never underestimate the power of human stupidity RAH

      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