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; }