在树状视图项目标题上添加一个图标[重复] 。

问题描述 投票:0回答:1

我想在WPF上的树形视图项中添加一个imageicon.怎么做呢,我正在编写一个树形视图,里面有我所有的电脑文件和dir的,我想让它更美观一点。

我试过了。

TreeViewItem item = new TreeViewItem(); 
item.Header = file icon image path;
item.Header += "file";

但它没有工作。

c# wpf treeviewitem
1个回答
0
投票
public partial class TreeViewSample : Page
    {
        public TreeViewSample()
        {
            InitializeComponent();

            Image tempImage = new Image(); var bitmapImage = new BitmapImage(new Uri("pack://application:,,,/images/configuration_32x32.png"));
            tempImage.Source = bitmapImage;

            TreeViewItem newItem = new TreeViewItem();
            TextBlock tempTextBlock = new TextBlock();
            tempTextBlock.Inlines.Add(tempImage);
            tempTextBlock.Inlines.Add("SomeText");
            newItem.Header = tempTextBlock;

            MyTreeView1.Items.Add(newItem);
        }
    }

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.