在WPF的TreeView中添加带图标的节点

.xaml代码为:


.xaml.cs代码为:

                    IStandaloneTable table1 = iTableCollection.get_StandaloneTable(i);
                    Image tempImage = new Image();
                    tempImage.Height = 20;
                    tempImage.Width = 30;
                    string path = System.IO.Path.GetFullPath("../../JWCH.AppMain.Ribbon/Resources/Images/attributetubiao.png");
                    System.Windows.Media.Imaging.BitmapImage bitmapImage = new System.Windows.Media.Imaging.BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute));
                    tempImage.Stretch = Stretch.Fill;
                    tempImage.Source = bitmapImage;
                    TextBlock tempTextBlock = new TextBlock();
                    tempTextBlock.Inlines.Add(table1.Name);
                    TreeViewItem mtrnode = new TreeViewItem();
                    StackPanel sp = new StackPanel();
                    sp.Orientation = System.Windows.Controls.Orientation.Horizontal;
                    sp.Children.Add(tempImage);
                    sp.Children.Add(tempTextBlock);
                    mtrnode.Header = sp;
                    treeTable.Items.Add(mtrnode);
                    treeTable.Items.Refresh();

 

你可能感兴趣的:(AE开发,wpf,arcgis)