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. ssh整合问题总结--使用struts2+Ajax+jquery验证用户名是否已被注册

    在用户模块中的用户注册需求上,通常要进行用户名是否已被注册的验证,今天正好写了这个需求,把详细代码和所遇到的问题贴过来.在使用struts2+ajax时候,通常我们会返回json类型的数据,但是像上面 ...

  2. (一)FlexViewer之整体框架解析

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.FlexViewer简介 FlexViewer框架为Esri提供的 ...

  3. 使用dynamic linq 解决自定义查询的若干弊端

    在项目中想必大家肯定是使用各种ORM, 如:NH.EF.fluent Data. 然而我在使用ORM的这几年中,随着数据库的结构越来越复杂,自定义查询的越来越多,但是一直没有解决一个问题就是自定义查询 ...

  4. Android中Application的应用

    当android程序启动时系统会创建一个 application对象,用来存储系统的一些信息.通常我们是不需要指定一个Application的,这时系统会自动帮我们创建,如果需要创建自己 的Appli ...

  5. ECMAScript 5中属性的特性值

    这是<JavaScript高级程序设计(第三版)>第六章相关内容的总结. ECMAScript中有两种属性:数据属性和访问器属性.每种属性都有四个特性值. 数据属性的四个特性值: [[Co ...

  6. C++ 面试 (1) 指针

    指针是C++中一类颇具特色的数据类型,允许直接操作内存地址,实现内存的动态分配.指针问题通常包括指针常量,常量指针,数组指针,指针数组,函数指针,指针传值等. 指针和引用的区别 非空区别.在任何情况下 ...

  7. maven pom中 设置远程仓库url

    <repositories> <!--<repository>--> <!--<id>spring-snapshots</id>--& ...

  8. linux中的通配符与正则表达式

    在linux中,有通配符及正则表达式,那么什么是通配符和正则表达式,什么时候用?   通配符 它是由shell解析,并且一般用于匹配文件名,实际上就是shell解释器去解析的特殊符号,linux系统通 ...

  9. 创建ASP.NET Core MVC应用程序(1)-添加Controller和View

    创建ASP.NET Core MVC应用程序(1)-添加Controller和View 参考文档:Getting started with ASP.NET Core MVC and Visual St ...

  10. Redis所需内存 超过可用内存怎么办

    爬虫和转载请注明原文地址:博客园蜗牛 http://www.cnblogs.com/tdws/p/5727633.html Redis所需内存 超过可用内存怎么办 Redis修改数据多线程并发—Red ...