知道是选择了整行还是WPF数据网格中的一列
如何判断是否选中了DataGrid中的整行 或者只有一列知道是选择了整行还是WPF数据网格中的一列,wpf,mvvm,datagrid,Wpf,Mvvm,Datagrid,如何判断是否选中了DataGrid中的整行 或者只有一列 (通过Binding或Command,我想保持MVVM的原则。)您可以将属性SelectionUnit设置为“FullRow”您可以将属性SelectionUnit设置为“FullRow”最后,我自己找到了一个解决方案 (非常奇怪,我在一次仔细的搜索中什么也没找到。) 以下是我所做的: 我将DataGrid的两个事件绑定到ViewModel中的命令 <i:EventTrigger EventName="Beginnin
(通过
Binding
或Command
,我想保持MVVM
的原则。)您可以将属性SelectionUnit设置为“FullRow”您可以将属性SelectionUnit设置为“FullRow”最后,我自己找到了一个解决方案
(非常奇怪,我在一次仔细的搜索中什么也没找到。)
以下是我所做的:
我将DataGrid的两个事件绑定到ViewModel中的命令
<i:EventTrigger EventName="BeginningEdit">
<i:InvokeCommandAction CommandParameter="{Binding CurrentCell.Column.DisplayIndex, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Command="{Binding DataContext.ColBeginEdit, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
</i:EventTrigger>
<i:EventTrigger EventName="CellEditEnding">
<i:InvokeCommandAction CommandParameter="{Binding CurrentCell.Column.Header, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Command="{Binding DataContext.ColEndEdit, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
</i:EventTrigger>
如果CurrentCellEdit大于0,则对该行进行符号编辑,否则不进行符号编辑
我在SelectedIndex上的行号,根据CurrentCellEdit,我还知道行中编辑的是哪一列
我希望找到一个更简单的方法,但这是我想到的唯一解决方案,为了保持MVVM的原则,我仍在尝试。最后,我自己找到了一个解决方案 (非常奇怪,我在一次仔细的搜索中什么也没找到。) 以下是我所做的: 我将DataGrid的两个事件绑定到ViewModel中的命令
<i:EventTrigger EventName="BeginningEdit">
<i:InvokeCommandAction CommandParameter="{Binding CurrentCell.Column.DisplayIndex, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Command="{Binding DataContext.ColBeginEdit, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
</i:EventTrigger>
<i:EventTrigger EventName="CellEditEnding">
<i:InvokeCommandAction CommandParameter="{Binding CurrentCell.Column.Header, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Command="{Binding DataContext.ColEndEdit, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
</i:EventTrigger>
如果CurrentCellEdit大于0,则对该行进行符号编辑,否则不进行符号编辑
我在SelectedIndex上的行号,根据CurrentCellEdit,我还知道行中编辑的是哪一列
我希望找到一种更简单的方法,但这是我想到的唯一解决方案,保持MVVM的原则,我仍在尝试..但我需要选择列,但我需要选择列