wpf TreeView 数据绑定
<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 数据绑定的更多相关文章
- wpf treeview 数据绑定 递归绑定节点
1.先上效果 将所有节点加入ComboBox数据源,在ComboBox中选择时下方Treeview显示该节点下的子节点. 1.xaml文件,将以下代码加入界面合适位置 <StackPanel&g ...
- WPF:数据绑定总结(1) https://segmentfault.com/a/1190000012981745
WPF:数据绑定总结(1) visual-studio c# 1.3k 次阅读 · 读完需要 16 分钟 0 一.概念:什么是数据绑定? WPF中的数据绑定:是在应用程序 UI 与业务逻辑之间建立 ...
- C# 关于变量使用范围容易犯错的问题(TreeView数据绑定为例)
asp.net做一个treeview数据绑定 绑定子节点时查询出来的数据正确,但在进行数据绑定时一直索引溢出 然后调试 ... 调试 ... 再调试... 依然很崩溃 想到了是变量定义后面共用后的问 ...
- WPF TreeView SelectedItemChanged called twice
How to avoid WPF TreeView SelectedItemChanged being called twice Very often, we need to execute some ...
- winform treeView 数据绑定
转载:http://www.jetwu.cn/archives/737 winform treeView 数据绑定 private void Form1_Load(object sender, Eve ...
- wpf Content数据绑定StringFormat起作用的原理和解决
原文:wpf Content数据绑定StringFormat起作用的原理和解决 <Window x:Class="WpfOne.Bind.Bind6" xmlns=" ...
- WPF TreeView HierarchicalDataTemplate
原文 WPF TreeView HierarchicalDataTemplate HierarchicalDataTemplate 的DataType是本层的绑定,而ItemsSource是绑定下层的 ...
- WPF TreeView Indent 减少节点的缩进
www.swack.cn - 原文链接:WPF TreeView Indent 减少节点的缩进 问题 最近一个需求,需要在界面中实现Windows资源管理器TreeView的界面.但是我发现,我做出的 ...
- WPF+MVVM数据绑定问题集锦
1. 数据绑定的问题 在使用数据绑定时,一般使用 ObservableCollection<T> 类,不使用list列表集合,因为list数据发生变化时,UI界面不更新,而Observa ...
- WPF TreeView的使用
WPF提供了treeView控件,利用该控件开发者可以将数据分层显示在树结构中.当然其中需要用到Binding的机制,有用的类包括:ObjectDataProvider.DataTemplate.Hi ...
随机推荐
- 智能指针 shared_ptr weak_ptr shared_from_this 笔记
shared_ptr 当指向对象的std::shared_ptr一创建,被管理对象的控制块SharedPtrControlBlock(参考下面的图)就建立了. 被管理的对象的控制块中有引用计数(ref ...
- Java内存分析利器——Eclipse Memory Analyzer工具的使用
一.如何下载Java程序的dump内存文件并离线导入到MemoryAnalyser工具进行分析 1.jps查看Java应用的pid jps 11584216168084 Launcher24792 ...
- 179. 最大数 (Medium)
问题描述 179. 最大数 (Medium) 给定一组非负整数 nums,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数. 注意: 输出结果可能非常大,所以你需要返回一个字符串而不是整数 ...
- 【剑指Offer】【数组】数组中出现次数超过一半的数字
题目:数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2.如果 ...
- go项目,出现too many open files
刚开始碰到这种异常,以为是代码写的有问题,准备抽时间去改,等有时间正式此问题的时候,发现这种问题一般只会在linux系统上出现,原因如下:linux系统限制了文件打开的最大文件句柄数,系统默认一般是1 ...
- SQL Server查看端口号及修改端口号
使用下面的SQL Command就可以查看SQL SERVER的端口号 exec sys.sp_readerrorlog 0,1,'listening' 下图查询结果中端口号为1433 修改端口号步骤 ...
- gitignore文件中忽略项不起作用的解决方法
在使用git的时候会遇到这样的情况,我们生产的一些class或者target的目录,我不能提交,这个时候我们需要使用gitignore,但是有的时候虽然添加了,但是不起作用. 情况:开发过程中,我们自 ...
- Vue2 常见问题汇总及解决方案
参考:https://mp.weixin.qq.com/s/6Wapb1bZLQaYv0zlip6ygg 1.安装超时(install timeout) 方案: cnpm : 国内对npm的镜像版本 ...
- 使用Telnet伪造邮件发送
注意:手抖就会败北,敲错就会白给,输入错误只能rset重新输入命令. 1.打开Telnet服务 搜索"程序和功能"->启用或关闭Windows功能->点选Telnet客 ...
- mysql8改密码
登录后执行语句 ALTER USER 'test'@'localhost' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY '新密码'; 修改Host范围 updat ...