[WPF]TreeViewのItemにアイコン追加

  • タグ:
  • タグはありません
TreeView TV = new TreeView();
//icon add
StackPanel sp = new StackPanel();
sp.Orientation = Orientation.Horizontal;
BitmapImage bmi = new BitmapImage();
bmi = new BitmapImage(new Uri("ITEM.png", UriKind.RelativeOrAbsolute));
Image img = new Image();
img.Source = bmi;
img.Height = 15;
img.Width = 15;
sp.Children.Add(img);
TextBlock tb = new TextBlock();
tb.Text = "TreeItem";
sp.Children.Add(tb);
 
//Add Parent’s Node
TreeViewItem item = new TreeViewItem();
item.Header = sp;
TV.Items.Add(item);