WPF中的树视图(xaml) [英] Tree view in Wpf(xaml)

查看:150
本文介绍了WPF中的树视图(xaml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有问题;
我已经在C#中像这样的代码创建了一个树形视图,但是
我该如何在wpf(xaml)中执行此操作? ?:confused:


I have a problem here ;
I''ve create a treeview in c# like this code ,but
How can I do this in wpf (xaml); ?:confused:


public void PopulateTreeView(  string dirValue, TreeNode parentNode )
     {
        /*   dirValue = inputTextBox.Text
             parentNode = directoryTreeView.Nodes[0] ..
         *
            directoryTreeView is a Treeview
         */


         // array stores all subdirectories in the directory
        string[] directoryArray =  Directory.GetDirectories( dirValue);

        try
        {
           // subdirectories are present
           if ( directoryArray.Length != 0 )
           {
              //  create new TreeNode,

              foreach ( string directory in directoryArray )
              {
                  // substringDirectory is a string defined in generall
          substringDirectory = Path.GetFileNameWithoutExtension(directory );


                  // current directory
                 TreeNode myNode = new TreeNode( substringDirectory );

                 // add current directory node to parent node
                 parentNode.Nodes.Add( myNode );

                 // recursive populate
                 PopulateTreeView( directory, myNode );
              }
           }
        }


        catch ( UnauthorizedAccessException )
        {
           parentNode.Nodes.Add( "Access denied !" );
        }
     }



:谢谢您的帮助,但我真的不明白你们的意思!您可以张贴代码段吗?(因为我是xaml的新手). :rose:



: Thanks for help, but I really didn''t understand what do you guys mean ! can you post snippet code ?(cause I''m new to xaml). :rose:

推荐答案

您可以使用几乎相同的方法进行操作.实际上,代码应该几乎可以完全按照已经拥有的方式删除(对Treeview本身进行适当的变量名更改).
You can do it pretty much the same way. In fact, the code should pretty much be able to be dropped in exactly the way you already have it (with the appropriate variable name change for the treeview itself).


您可以使用TreeViewItem类在WPF中,否则将您的输出写入XML文件,并使用与XAML中TreeView的源相同的文件.
You can use TreeViewItem class in WPF or else write your output in a XML file and use the same file as the source of TreeView in XAML.


这篇关于WPF中的树视图(xaml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆