当前位置:网站首页>C recursively obtains all files under the folder and binds them to the treeview control
C recursively obtains all files under the folder and binds them to the treeview control
2022-07-25 00:29:00 【solar storm】
C# Recursively get all the files under the folder And bind to TreeView Control
introduction :C# Recursively get all the files under the folder And bind to TreeView Control code snippet
One 、 code snippet
- 1、 The front-end code :
<TreeView x:Name="BookMarkTree" SelectedItemChanged="BookMarkTree_SelectedItemChanged" BorderThickness="2" >
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Name}"></TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
- 2、 Back end code
// Data node to be bound
public class Node
{
public string Name {
get; set; }
public List<Node> Children {
set; get; }
public Node()
{
Children = new List<Node>();
}
}
// Recursively get files and generate nodes
public Node GetChildren(DirectoryInfo directoryInfo)
{
Node node = new Node() {
Name = directoryInfo.Name };
var subDirectory = directoryInfo.GetDirectories();
var files = directoryInfo.GetFiles();
if(files.Length !=0)
{
foreach (var item in files)
{
// Get the file name , Remove suffix
node.Children.Add(new Node {
Name = item.Name.Replace(".html","")});
}
}
if (subDirectory.Length != 0)
{
foreach (var item in subDirectory)
{
// Continuous iteration
node.Children.Add(GetChildren(item));
}
}
return node;
}
// binding treeview Select response
private void BookMarkTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
TreeView treeView = (TreeView)sender;
Node item = (Node)treeView.SelectedItem;
// The following can be true of item To operate
}
Two 、 Use cases
// Access to the node
DirectoryInfo directoryInfo = new DirectoryInfo("./Documents/Help/Pages");
List<Node> nodes = new List<Node>();
nodes.Add(GetChildren(directoryInfo));
// by TreeView binding ItemsSource
BookMarkTree.ItemsSource = nodes;
3、 ... and 、 test result
nodes Data view :

Software screenshot :

边栏推荐
- UART
- Detailed explanation of alexnet of paddlepaddle paper series (with source code)
- jquer $(‘div li‘) $(‘div,li‘) $(‘div>li‘) $(‘div‘,‘li‘)
- Live broadcast preview | online seminar on open source security governance models and tools
- 2022 Henan Mengxin League game 2: Henan University of technology I - 22
- Multi table query of SQL
- [mindspore ascend] [user defined operator] graph_ In mode, customize how to traverse tensor
- [hero planet July training leetcode problem solving daily] 24th line segment tree
- 3. Pressure test
- Grafana - influxdb visual K6 output
猜你喜欢

每周小结(*66):下一个五年

Pit record: typeerror:'module'object is not callable
![[mindspore] [training warning] warning when executing training code](/img/5a/978889301bdd02d6474c6e5723ad97.jpg)
[mindspore] [training warning] warning when executing training code

Financial RPA robot enables enterprises to open a new era of intelligence

js && ||

Sql文件导入数据库-保姆级教程
![[mindspore] [xception model] script statement is suspected to be wrong](/img/86/3174f9edadf4b815a76678551cbfa5.jpg)
[mindspore] [xception model] script statement is suspected to be wrong
![[LeetCode周赛复盘] 第 303 场周赛20220724](/img/ba/0f16f1f42e4a2593ec0124f23b30d7.png)
[LeetCode周赛复盘] 第 303 场周赛20220724

Branch and loop statements in C language learning
![[help] mindspire training based on ascend910 cannot reproduce the model effect on GPU](/img/b5/c02ef57526d208b02dfa00189e9ecb.jpg)
[help] mindspire training based on ascend910 cannot reproduce the model effect on GPU
随机推荐
SQL file import database - Nanny level tutorial
2022 Henan Mengxin League game 2: Henan University of technology I - 22
Install and configure php5-7 version under centos7.4
[untitled]
[mindspore ascend] [running error] graph_ In mode, run the network to report an error
Branch and loop statements in C language learning
数组中只出现一次的两个数字
Number of palindromes in question 5 of C language deduction (two methods)
The font changes with the change of the form
Install K6 test tool
Measurement and Multisim Simulation of volt ampere characteristics of circuit components (engineering documents attached)
QT learning - using database singleton to complete login matching + registration function
Grafana - influxdb visual K6 output
Heap and stack in embedded development
Internal network mapping port to external network
[hero planet July training leetcode problem solving daily] 24th line segment tree
Weekly summary (*66): next five years
The number of palindromes in question 9 of C language deduction. Two pointer array traversal method
Daily question 1 · 1260. Two dimensional network migration · simulation
torch.nn.SyncBatchNorm.convert_ sync_ Mindspore usage corresponding to batchnorm