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 ...
随机推荐
- h5项目自适应字体和宽高。用rem
已知: 1.浏览器默认的字号是16px,html{font-size: 87.5%;}(16*0.875 = 14px). 2.css中的单位换算:rem 与 px 的换算为 px = rem * 设 ...
- 如何将一个h5ad文件内部添加一个csv文件作为属性obsm
问题展开 学习生物信息的时候发现,需要将一个M * N的csv文件作为anndata文件的.X部分,一个M * 2的csv文件作为anndata文件的空间位置信息标识. 首先先读M*N的文件 myda ...
- [Vs和Reshaper]Vs Studio配合Resharper插件,某些快捷键无法使用的情况,Alt+F7
一直使用Alt+F7来查找变量或者类型的使用位置 家里面的电脑某一天不可以用了,按了没有任何反应 后来查到竟然是被别的软件快捷键覆盖了 Alt+F7是被Nvidia GeForce覆盖了,关掉它或者修 ...
- HttpClient Post 提交表单数据
运行环境 .net 4.6.1 //为防止因HTTPS证书认证失败造成API调用失败,需要先忽略证书信任问题 var sslHandler = new HttpClientHandler() { }; ...
- UE打LOG整理
Kismet库 蓝图方法cpp使用 例:打LOG:Print String 蓝图节点的鼠标tips:Target is Kismet System Library #include "Run ...
- python 非阻塞线程对话框,非qt(解决qt MessageBox使用线程时候卡死问题)
def msg_okbox(self, strinfo, isYesno=False): if isYesno: return win32api.MessageBox(None, strinfo, & ...
- Vue基础之v-if与v-show
Show Time! 说再多不如直接上效果: (一)v-if <div id="app"> <div v-if="flag" class=&q ...
- H5移动端跳转唤起QQ在线客服与跳转支付宝
以下两段代码都是找了很久的,在某个删库跑路的支付商那里找到的! H5移动端跳转QQ 实现在线客服 <a href="mqqwpa://im/chat?chat_type=wpa& ...
- Openssh升级到9.2版本
操作系统:centos7.6 1.安装依赖 yum install gcc gcc-c++ zlib-devel pam-devel openssl-devel make vim wget -y 备份 ...
- 090_Java
在JAVA程序中,性能问题的大部分原因并不在于JAVA语言,而是程序本身.养成良好的编码习惯非常重要,能够显著地提升程序性能. ● 1. 尽量在合适的场合使用单例 使用单例可以减轻加载的负担,缩短加载 ...