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

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top