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. 【Java心得总结六】Java容器中——Collection

    在[Java心得总结五]Java容器上——容器初探这篇博文中,我对Java容器类库从一个整体的偏向于宏观的角度初步认识了Java容器类库.而在这篇博文中,我想着重对容器类库中的Collection容器 ...

  2. 相克军_Oracle体系_随堂笔记009-检查点队列

    1.检查点队列 checkpoint queue RBA 日志块地址 redo block address LRBA 第一次被脏的地址 HRBA 最近一次被脏的地址 on disk rba 重做日志( ...

  3. 用react的ReactCSSTransitionGroup插件实现简单的弹幕动画

    1,开始的思路 公司想做直播方面的项目,并想加入弹幕的功能,直播的页面已经作为一个组件放在了用react+redux写好的一个网站项目上.所以技术老大让我研究下如何用react实现弹幕的功能.下面我就 ...

  4. js实现动画效果框架

    RT,是参照慕课的教程做的.两个多小时的教程,看完了然后晚上的时候做了下,看的时候感觉明白了,但其实做的时候还是有很多小细节需要处理的. 上代码,思想什么的直接去慕课看教程就好了.点击这里 注释也比较 ...

  5. Android置底一个View后运行报错

    大致问题是 放一个LinearLayout ID @+id/layout ,然后在它上面放一个button 设置android:layout_above="@id/layout" ...

  6. PHP之call user func()函数

    在实际开发中通常会遇到这样的问题,决定调用某个函数是通过传入的参数决定的,例如: $functionName=$_post['functionName']; 接着我们需要访问一个叫$functionN ...

  7. 分离的思想结合单链表实现级联组件:CascadeView

    本文介绍自己最近做省市级联的类似的级联功能的实现思路,为了尽可能地做到职责分离跟表现与行为分离,这个功能拆分成了2个组件并用到了单链表来实现关键的级联逻辑,下一段有演示效果的gif图.虽然这是个很常见 ...

  8. 【转】App开放接口api安全性—Token签名sign的设计与实现

    前言 在app开放接口api的设计中,避免不了的就是安全性问题,因为大多数接口涉及到用户的个人信息以及一些敏感的数据,所以对这些接口需要进行身份的认证,那么这就需要用户提供一些信息,比如用户名密码等, ...

  9. healthMonitoring与运行状况监视

    配置针对应用程序的运行状况监视的一个服务 配置节内容比以往的较为复杂,如下 <healthMonitoring Enabled="true|false" heartbeatI ...

  10. Lind.DDD.Events事件总线~自动化注册

    回到目录 让大叔兴奋的自动化注册 对于领域事件之前说过,在程序启动时订阅(注册)一些事件处理程序,然后在程序的具体位置去发布(触发)它,这是传统的pub/sub模式的体现,当然也没有什么问题,为了让它 ...