WPF TreeView遍历硬盘
<Window x:Class="TreeFileSystem.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TreeView Name="treeFileSystem" TreeViewItem.Expanded="treeFileSystem_Expanded_1">
</TreeView>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TreeFileSystem
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
TreeViewItem item = new TreeViewItem();
item.Tag = drive;
item.Header = drive.ToString();
item.Items.Add("*");
treeFileSystem.Items.Add(item);
}
}
private void treeFileSystem_Expanded_1(object sender, RoutedEventArgs e)
{
TreeViewItem item = (TreeViewItem)e.OriginalSource;
item.Items.Clear();
DirectoryInfo dir;
if (item.Tag is DriveInfo)
{
DriveInfo drive = (DriveInfo)item.Tag;
dir = drive.RootDirectory;
}
else
{
dir = (DirectoryInfo)item.Tag;
}
try
{
foreach (DirectoryInfo subDir in dir.GetDirectories())
{
TreeViewItem newItem = new TreeViewItem();
newItem.Tag = subDir;
newItem.Header = subDir.ToString();
newItem.Items.Add("*");
item.Items.Add(newItem);
}
}
catch
{
}
}
}
}
WPF TreeView遍历硬盘的更多相关文章
- WPF TreeView SelectedItemChanged called twice
How to avoid WPF TreeView SelectedItemChanged being called twice Very often, we need to execute some ...
- WPF TreeView HierarchicalDataTemplate
原文 WPF TreeView HierarchicalDataTemplate HierarchicalDataTemplate 的DataType是本层的绑定,而ItemsSource是绑定下层的 ...
- WPF TreeView Indent 减少节点的缩进
www.swack.cn - 原文链接:WPF TreeView Indent 减少节点的缩进 问题 最近一个需求,需要在界面中实现Windows资源管理器TreeView的界面.但是我发现,我做出的 ...
- WPF TreeView 后台C#选中指定的Item, 需要遍历
private TreeViewItem FindTreeViewItem(ItemsControl container, object item) { ...
- WPF TreeView递归遍历相关方法
/// <summary> /// 递归改变组织树选中状态. /// </summary> /// <param name="org">< ...
- WPF TreeView的使用
WPF提供了treeView控件,利用该控件开发者可以将数据分层显示在树结构中.当然其中需要用到Binding的机制,有用的类包括:ObjectDataProvider.DataTemplate.Hi ...
- WPF TreeView 虚拟化-设置滚动到选中项
前言 列表滚动到具体的数据项? ListBox提供了简易快捷的滚动定位函数ScrollIntoView. TreeView树状结构列表,则没有此类方法,无法与ListBox一样,直接设置滚动到具体的数 ...
- 【原创】WPF TreeView带连接线样式的优化(WinFrom风格)
一.前言 之前查找WPF相关资料的时候,发现国外网站有一个TreeView控件的样式,是WinFrom风格的,样式如下,文章链接:https://www.codeproject.com/tips/67 ...
- wpf TreeView
<Window x:Class="WpfTutorialSamples.TreeView_control.TreeViewDataBindingSample" ...
随机推荐
- valgrind,arm-linux交叉编译
1. 下载及解压valgrind-3.9.0 2.CC=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux ...
- PatentTips - 在物联网中进行数据过滤的方法和装置
背景技术 [0001] 本发明涉及物联网,特别涉及在物联网进行数据过滤的方法和装置. [0002] 物联网是新一代信息技术的重要组成部分,特指物物相连的网络.具体地,物联网是指通过各种信息传感设备,如 ...
- Sift算子特征点提取、描述及匹配全流程解析
Sift之前的江湖 在Sift横空出世之前,特征点检测与匹配江湖上占据霸主地位的是角点检测家族.先来探究一下角点家族不为人知的恩怨情仇. 角点家族的族长是Moravec在1977年提出的Moravec ...
- Navigation Pane不能设置显示标题
https://msdn.microsoft.com/VBA/Word-VBA/articles/view-showheading-method-word https://social.msdn.mi ...
- 在ArcEngine下实现图层属性过滤的两种方法
转自chanyinhelv原文 在ArcEngine下实现图层属性过滤的两种方法 Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* ...
- [TypeScript] Simplify asynchronous callback functions using async/await
Learn how to write a promise based delay function and then use it in async await to see how much it ...
- Rational Rose2007无法正常启动解决方式
安装完Rational Rose发现无法正常启动,我遇到了下面两个问题,希望能帮到同样经历的同学. 问题一: 安装完Rational Rose后不能用,提演示样例如以下:无法启动此程序,由于计算机中丢 ...
- Local database deployment problems and fixtures
/*By Jiangong SUN*/ After encountering some problems in deploying databases to local server, here ar ...
- 自己动手写shell命令之ls
linux下ls命令(支持-R參数)的c语言实现: #include <stdio.h> #include <sys/types.h> #include <dirent. ...
- 一个完整的Erlang应用
http://blog.chinaunix.net/uid-25876834-id-3308693.html 这里介绍构建一个完整的Erlang/OTP应用的例子,最后还给出了一个在实际生成环境中,如 ...