<Window x:Class="TsyCreateProjectContent.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TsyCreateProjectContent"
mc:Ignorable="d"
Loaded="Window_Loaded_V1"
Title="test" Height="525" Width="540" ResizeMode="NoResize">

<Grid Height="525" VerticalAlignment="Top" ShowGridLines="False">

<TreeView Grid.Row="0" Grid.Column="0" x:Name="FolderView" Canvas.Top="1" Canvas.Bottom="1" VerticalAlignment="Stretch"
MouseLeftButtonUp="FolderView_MouseLeftButtonUp" Margin="5,5,15,5" Width="500">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:TreeViewData}" ItemsSource="{Binding Path=Children}">
<StackPanel Orientation="Horizontal">
<Image Margin="3" Width="20" Source="{Binding ImgName}"/>
<TextBlock VerticalAlignment="Center" Text="{Binding HeaderName }" Tag="{Binding TagValue}"/>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsSelected" Value="{Binding IsSelected}" />
<Setter Property="IsExpanded" Value="{Binding IsExpanded}" />
</Style>
</TreeView.ItemContainerStyle>

</TreeView>

</Grid>
</Window>

private void Window_Loaded_V1(object sender, RoutedEventArgs e)
{
List<TreeViewData> rootList = new List<TreeViewData>();
TreeViewData rootItem = new TreeViewData();
rootItem.HeaderName = "我的电脑";
rootItem.TagValue = "我的电脑";
rootItem.ImgName = "Images/windows.png";
rootItem.IsExpanded = true;
rootItem.IsSelected = true;
rootItem.Children = new List<TreeViewData>();
rootList.Add(rootItem);

// 将其添加到主树视图
//FolderView.Items.Add(rootItem);
DriveInfo[] drivers = DriveInfo.GetDrives();

// 获取电脑上的每个逻辑驱动器
foreach (var drive in Directory.GetLogicalDrives())
{
var childItem = new TreeViewData();
childItem.HeaderName = drive;
childItem.TagValue = drive;
childItem.ImgName = "Images/drive.png";
rootItem.IsExpanded = true;
rootItem.IsSelected = false;
childItem.Children = new List<TreeViewData>();
rootItem.Children.Add(childItem);
}
FolderView.ItemsSource = rootList;

}

wpf TreeView 数据绑定的更多相关文章

  1. wpf treeview 数据绑定 递归绑定节点

    1.先上效果 将所有节点加入ComboBox数据源,在ComboBox中选择时下方Treeview显示该节点下的子节点. 1.xaml文件,将以下代码加入界面合适位置 <StackPanel&g ...

  2. WPF:数据绑定总结(1) https://segmentfault.com/a/1190000012981745

    WPF:数据绑定总结(1) visual-studio c# 1.3k 次阅读  ·  读完需要 16 分钟 0 一.概念:什么是数据绑定? WPF中的数据绑定:是在应用程序 UI 与业务逻辑之间建立 ...

  3. C# 关于变量使用范围容易犯错的问题(TreeView数据绑定为例)

    asp.net做一个treeview数据绑定 绑定子节点时查询出来的数据正确,但在进行数据绑定时一直索引溢出 然后调试 ... 调试 ... 再调试... 依然很崩溃  想到了是变量定义后面共用后的问 ...

  4. WPF TreeView SelectedItemChanged called twice

    How to avoid WPF TreeView SelectedItemChanged being called twice Very often, we need to execute some ...

  5. winform treeView 数据绑定

    转载:http://www.jetwu.cn/archives/737 winform treeView 数据绑定 private void Form1_Load(object sender, Eve ...

  6. wpf Content数据绑定StringFormat起作用的原理和解决

    原文:wpf Content数据绑定StringFormat起作用的原理和解决 <Window x:Class="WpfOne.Bind.Bind6" xmlns=" ...

  7. WPF TreeView HierarchicalDataTemplate

    原文 WPF TreeView HierarchicalDataTemplate HierarchicalDataTemplate 的DataType是本层的绑定,而ItemsSource是绑定下层的 ...

  8. WPF TreeView Indent 减少节点的缩进

    www.swack.cn - 原文链接:WPF TreeView Indent 减少节点的缩进 问题 最近一个需求,需要在界面中实现Windows资源管理器TreeView的界面.但是我发现,我做出的 ...

  9. WPF+MVVM数据绑定问题集锦

    1.  数据绑定的问题 在使用数据绑定时,一般使用 ObservableCollection<T> 类,不使用list列表集合,因为list数据发生变化时,UI界面不更新,而Observa ...

  10. WPF TreeView的使用

    WPF提供了treeView控件,利用该控件开发者可以将数据分层显示在树结构中.当然其中需要用到Binding的机制,有用的类包括:ObjectDataProvider.DataTemplate.Hi ...

随机推荐

  1. Oracle中的sql脚本语言中的循环语句介绍

    --sql脚本语言的循环介绍:--1.goto循环点.declare  x number;begin  x:=0;--变量初始化:  <<repeat_loop>>--设置循环 ...

  2. hash和hash tree

    在理想情况下,我们希望不经过任何比较,一次存取便能得到所查的记录,那就必须在记的存储位置和它的关键字之间建立一个确定的对应关系,使每个关键字和一个唯一的存储位置对应,因而在查找时候,根据这个对应关系与 ...

  3. corundum:100GNIC学习(三)——恢复工程

    前文:(一)https://www.cnblogs.com/shroud404/p/15364812.html (二)https://www.cnblogs.com/shroud404/p/15412 ...

  4. 【7】java之正则表达式

    一.正则标记 ​ 所有的正则可以使用的标记都在 java.util.regex.Pattern 类里定义. 1.1 单个字符 字符:表示由一位字符所组成: \\\\:表示转义字符"\\&qu ...

  5. UVM——通过一个简单的testbench来了解UVM组件的phase执行顺序

    先写好一个top.sv 查看代码 // 导入VCS或者Modelsim自带的UVM库和宏 `include "uvm_macros.svh" import uvm_pkg::*; ...

  6. winform应用程序

    1.winform桌面应用程序是一种智能的客户端技术,我们可以使用winform应用程序帮助我们获得信息或者传输信息等 2.属性 Names:在后台要获得前台的控件对象,需要使用Name属性 Visi ...

  7. Nodejs杀死本地应用(win)

    windows端nodejs检查应用运行并杀死. import {exec, execSync} from "child_process" import {decode} from ...

  8. 多点DLT (Direct Linear Transformation) 算法

    阅读前可以先参看上一篇代数视觉博客: 四点DLT (Dierct Linear Transformation) 算法 对于大于4个点的数据点来进行 DLT 算法变换, 如果数据点的标注都十分准确,那么 ...

  9. Java面向对象之封装详解

    封装详解 封装 该露的露,该藏的藏 1.我们程序设计要追求"高内聚.低耦合".高内聚:类的内部数据操作细节自己完成,不允许外部干涉:低耦合:仅暴露少量的方法给外部使用. 封装(数据 ...

  10. Windchill_二次开发新手入门常用的API

    Windchill_二次开发新手入门常用的API 1.根据零件名称/编码 得到该零件 wt.clients.prodmgmt.WTPartHelper.findPartByName(name) ;   ...