WPF中的树视图(xaml)

编程入门 行业动态 更新时间:2024-10-07 04:24:43
本文介绍了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)

本文发布于:2023-11-12 20:51:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582503.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   WPF   xaml

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!