WPF的DataGrid全行选择 [英] WPF DataGrid full row selection

查看:173
本文介绍了WPF的DataGrid全行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用WPF和.NET 4.0。最近在我的节目之一,我使用GridView控件与ListView控件到DataGrid中切换。

I'm using WPF and .NET 4.0. Recently in one of my programs I switched from using ListView with GridView to DataGrid.

我希望能够选择并高亮显示整排像我得以在ListView中的事情。

I want to be able to select and highlight the whole row like I was able to do in ListView.

在ListView控件,当我点击右侧的最后一列空的空间,我仍然能够选择行。整排被高亮显示,不仅将细胞

In ListView, when I click on the empty space right from the last column, I'm still able to select the row. The whole row is highlighted, not only the cells.

在DataGrid中,设置的SelectionMode =单和SelectionUnit =FullRow后,该行是可选的只有当我在它点击任何单元格,而不是在正确的最后一栏的空白区域。

In DataGrid however, after setting SelectionMode="Single" and SelectionUnit="FullRow", the row is selectable only when I click on any cell in it, not in the empty space right to the last column.

如何使用行为突出的ListView从这里?

How can I use the highlighting behavior from ListView here?

推荐答案

有两种解决方法:


  1. 设置的最后一列的宽度在DataGrid到WIDTH =*。

  2. 第二个解决方案是一个解决方法。最后柱后添加额外的空栏(即​​没有设置它的头部和结合特性)和它的宽度为宽度=*

我个人preFER第一个解决方案,它比第二个更干净。

I personally prefer the first solution, it's more clean than the second one.

这篇关于WPF的DataGrid全行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆