How to add images/icons in WPF Tree View from code behind

  • Thread starter Thread starter DNB
  • Start date Start date
D

DNB

How to add images/icons in WPF Tree View from code behind

Following is my WPF code, can someone guide me how can I add images from
codebehind

<TreeView Grid.Row="2" FontFamily="Courier" FontSize="14" Name="tree"
TreeViewItem.Selected="TreeView_ItemSelected"
TreeViewItem.Expanded="TreeView_ItemExpanded" >

</TreeView>

<TreeViewItem FontFamily="Courier" Foreground="Red" Background="Yellow"
FontSize="14" />



.....

TreeViewItem Newitem = new TreeViewItem();

Newitem.Tag = cNodeSite + u.SiteID.ToString();

Newitem.Header = u.SiteName.ToString();

Newitem.Foreground = System.Windows.Media.Brushes.Green;

Newitem.Items.Add("*");

item.Items.Add(Newitem);

tree.Items.Add(item);

.....

.....

Thanks

DNB
 
DNB,

Look at the Header property or the HeaderTemplate property (depending on
how you want to effect the TreeViewItem). TreeViewItem derives from
HeaderedItemsControl which has the item to display, and its children. In
this case, you want the Header.
 
Back
Top