silverlight利用代码添加带图标的treeviewItem

如何利用代码添加带图标的treeviewItem?

代码如下:
TreeViewItem CreateTreeViewItem(MyClass cls)
        {
            StackPanel panel = new StackPanel();
            panel.Orientation = Orientation.Horizontal;
 
            BitmapImage bitmap = new BitmapImage();
            bitmap.BeginInit();
            bitmap.UriSource = new Uri("../Images/Angel.png",UriKind.Relative);
            bitmap.EndInit();
 
            Image img = new Image();
            img.Width = img.Height = 20;
            img.Source = bitmap;
 
            TextBlock tb = new TextBlock();
            tb.Text = cls.Name;
 
            panel.Children.Add(img);
            panel.Children.Add(tb);
 
            TreeViewItem tvi = new TreeViewItem();
            tvi.Header = panel;
            tvi.Tag = cls;
            return tvi;
        }


 

 

posted @ 2010-07-08 16:42  春文秋武  阅读(214)  评论(0编辑  收藏  举报