WPF 显示文件列表中使用 ListBox 变到ListView 最后使用DataGrid

故事背景:

  需要检索某目录下文件,并列出来,提供选择和其他功能。

第一版需求:

  列出文件供选择即可,代码如下:

<ListBox Name="multiSelectFileLst" ItemsSource="{Binding FileList}" Grid.Row="" Grid.Column="" >
<ListBox.ItemTemplate >
<DataTemplate >
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Border Margin="5,1,5,1" Padding="" BorderBrush="Green" BorderThickness="" CornerRadius="">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="" ></ColumnDefinition>
<ColumnDefinition Width="Auto" ></ColumnDefinition>
<ColumnDefinition Width="" ></ColumnDefinition>
</Grid.ColumnDefinitions> <CheckBox Content="{Binding FileName}" ToolTip="{Binding FileName}" IsChecked="{Binding IsSelected}"/>
<Button Content="查看" Width="" HorizontalAlignment="Left" Grid.Column=""
Command="{Binding DataContext.OpenFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}" CommandParameter="{Binding ExcelFilePath}" /> </Grid>
</Border>
</Grid> </DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

可取之处:

  使用Border 画的边框还不错。

第二版需求:

  需要添加文件的目录一项,因此要添加列标题,该用ListView实现,改动较小:

  

<ListView Name="multiSelectFileLst" ItemsSource="{Binding FileList}" Grid.Row="" Grid.Column="" >
<ListView.View>
<GridView >
<GridViewColumn Header="文件名">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Content="{Binding FileName}" ToolTip="{Binding FileName}" IsChecked="{Binding IsSelected}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="文件目录">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding FolderPath}" ToolTip="{Binding FolderPath}" Foreground="Black" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="查看文件">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="查看" Width="" HorizontalAlignment="Left"
Command="{Binding DataContext.OpenFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}" CommandParameter="{Binding ExcelFilePath}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>

最后,个人觉得默认样式不好看,改为使用actiprosoftware的ThemedDataGrid:

  

<datagrid:ThemedDataGrid Name="multiSelectFileLst" ItemsSource="{Binding FileList}" Grid.Row="" Grid.Column=""
AutoGenerateColumns="False" CanUserAddRows="False" CanUserResizeRows="False" CanUserDeleteRows="False"
AreRowDetailsFrozen="False" CanUserSortColumns="False" CanUserReorderColumns="False"
HeadersVisibility="Column" SelectionUnit="FullRow"
> <datagrid:ThemedDataGrid.Columns>
<DataGridTemplateColumn Header="文件名" IsReadOnly="True" Width="auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Content="{Binding FileName}" ToolTip="{Binding FileName}" IsChecked="{Binding IsSelected}" Margin="0,0,20,0" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn >
<DataGridTemplateColumn Header="文件目录" IsReadOnly="True" Width="auto" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding FolderPath}" ToolTip="{Binding FolderPath}" Margin="20,0,20,0" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn >
<DataGridTemplateColumn Header="查看文件" IsReadOnly="True" Width="" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="查看" HorizontalAlignment="Left" Width=""
Command="{Binding DataContext.OpenFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
CommandParameter="{Binding ExcelFilePath}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn >
</datagrid:ThemedDataGrid.Columns>
</datagrid:ThemedDataGrid>

其中存在疑问:ListBox中的模板长度设置,没有随界面缩放,后续解决了补上。

  

WPF 显示文件列表中使用 ListBox 变到ListView 最后使用DataGrid的更多相关文章

  1. 在滚动列表中实现视频的播放(ListView & RecyclerView)

    英文原文:Implementing video playback in a scrolled list (ListView & RecyclerView) 本文将讲解如何在列表中实现视频播放. ...

  2. Android 在滚动列表中实现视频的播放(ListView & RecyclerView)

    这片文章基于开源项目: VideoPlayerManager. 所有的代码和示例都在那里.本文将跳过许多东西.因此如果你要真正理解它是如何工作的,最好下载源码,并结合源代码一起阅读本文.但是即便是没有 ...

  3. 列表控件ListBox关联的MFC中的类:CListBox

    列表控件ListBox关联的MFC中的类:CListBox ######################################################## 1.在列表的结尾添加一项: ...

  4. WPF中的ListBox实现按块显示元素的方法

    本文实例讲述了WPF中的ListBox实现按块显示元素的方法.分享给大家供大家参考,具体如下: 注意:需要设置ListBox的属性 ScrollViewer.HorizontalScrollBarVi ...

  5. Confluence 6 多媒体文件和在页面中显示文件列表

    多媒体文件 文件的预览同时也支持 MP3 音频和 MP4 视频文件.Confluence 使用 HTML 5 来播放附加的音频和视频文件.这个意味着这些文件类型的文件格式,用户可以在支持的浏览器中直接 ...

  6. 年度巨献-WPF项目开发过程中WPF小知识点汇总(原创+摘抄)

    WPF中Style的使用 Styel在英文中解释为”样式“,在Web开发中,css为层叠样式表,自从.net3.0推出WPF以来,WPF也有样式一说,通过设置样式,使其WPF控件外观更加美化同时减少了 ...

  7. React 点击删除列表中对应项(React 获取DOM中自定义属性)

    点击删除按钮,删除列表中对应项本来是React比较基础的应用,可是应用情况变得复杂了以后,我还真想了一会儿才搞定. 简化一下应用场景:点击新增按钮,增加一条输入框,点击输入框旁边的按钮,删除该输入框( ...

  8. Python 去除列表中重复的元素

    Python 去除列表中重复的元素 来自比较容易记忆的是用内置的set l1 = ['b','c','d','b','c','a','a'] l2 = list(set(l1)) print l2 还 ...

  9. OOP中的逆变和协变

    逆变和协变在存在于强类型语言中,尽管非常少提及.可是里面蕴含了面向对象的世界观.感谢和我一起讨论这个问题的人. 这里用了C#.Scala的语法作为演示样例.事实上逆变和协变的概念跟语言本身关系不大.事 ...

随机推荐

  1. (十七)WebGIS中距离及面积测量的原理和实现以及坐标转换的简单介绍

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 在这一章里我们将讨论基础工具栏中另外两个常用工具:距离测量工 ...

  2. Android之assets资源

    assets目录下存放的原生资源文件,通过getAssets()方法获取. 使用: InputStream inputStream; try { inputStream = getAssets().o ...

  3. 放养的小爬虫--豆瓣电影入门级爬虫(mongodb使用教程~)

    放养的小爬虫--豆瓣电影入门级爬虫(mongodb使用教程~) 笔者声明:只用于学习交流,不用于其他途径.源代码已上传github.githu地址:https://github.com/Erma-Wa ...

  4. 应用程序启动管理 Winform版

    ★前言      开发这个小工具的想法主要是机器中安装了数据库,每次设置开机启动数据库服务的话,则系统启动很慢,每次都得手动到服务管理器中停止服务,很是繁琐,相信不少做开发的朋友会遇到同样的问题,就有 ...

  5. JDK,JRE,JVM分别是什么?

    JDK(Java Development Kit) 是 Java 语言的软件开发工具包(SDK). JDK包含的基本组件包括: javac – 编译器,将源程序转成字节码 jar – 打包工具,将相关 ...

  6. 第 31 章 项目实战-PC端固定布局[1]

    学习要点: 1.准备工作 2.创建项目 3.网站结构 4.CSS选择器 5.完成导航 主讲教师:李炎恢 本章主要开始使用学习用HTML5和CSS3来构建Web页面,第一个项目采用PC端 固定布局来实现 ...

  7. JAVA 链表操作:循环链表

    主要分析示例: 一.循环链表简述 二.单链表循环链表 三.双链表循环链表 一.循环链表简述 循环链表即链表形成了一个循环的结构,尾节点不再指向NULL,而是指向头节点HEAD,此时判定链表的结束是尾节 ...

  8. PHP工作笔记:yii2各种功能汇总

    数据库操纵: 基础知识:数据库基础 查询语句: 使用yii migrate管理.生成数据库 Yii2 AR find用法 Yii2.0 对数据库 查询的一些简单的操作 修改语句: Yii 修改数据的两 ...

  9. python基础之条件控制与循环

    Python3 条件控制 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户 ...

  10. HTML思维导图