【发布时间】:2017-12-07 20:08:32
【问题描述】:
我的 WPF 应用程序中有 DataGrid,我想在 SelectedCellsChanged 事件中运行一个函数,但前提是该行未完全选中,如果用户单击该行的标题会发生这种情况。
我的表格只有一列。
我试过下面的代码,rowContainer.IsSelected 的值总是假的。
我该怎么做?
Private Sub DataGridEx_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles Me.SelectionChanged
If SelectedCells.Count <> 1 Then
Exit Sub
End If
If Not SelectedCells.First.Item.ToString.Contains("NewItemPlaceholder") Then
Me.TheDispatcher.BeginInvoke(
Sub()
Dim cell = SelectedCells.First
Dim index = Items.IndexOf(cell.Item) + 1
Dim rowContainer As DataGridRow = ItemContainerGenerator.ContainerFromIndex(index)
If rowContainer IsNot Nothing Then
If Not rowContainer.IsSelected Then
' run a function here
End If
End If
End Sub,
DispatcherPriority.Input)
End If
End Sub
【问题讨论】: