既然沒有人能給出提示或幫助我有點挖倒在internetzz並找到了解決方法,希望能幫助別人需要:
Private Sub dgKasStaatRegels_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles dgKasStaatRegels.Loaded
Try
Dim CellFocusedChangedHandler As New RoutedEventHandler(AddressOf FocusChangedHandler)
[AddHandler](DataGridCell.GotKeyboardFocusEvent, CellFocusedChangedHandler)
Catch ex As Exception
WriteErrorLog("ucKasStaat", "dgKasStaatRegels_Loaded", ex)
End Try
End Sub
Private Sub FocusChangedHandler(sender As Object, args As RoutedEventArgs)
If args.RoutedEvent.RoutingStrategy = RoutingStrategy.Bubble Then
Dim DataGridCellObj As FrameworkElement = TryCast(args.OriginalSource, FrameworkElement)
If Keyboard.IsKeyDown(Key.Tab) Then
If DataGridCellObj IsNot Nothing Then
Dim txtb As TextBox = TryCast(DataGridCellObj, TextBox)
If txtb IsNot Nothing Then txtb.Focus()
Dim cb As ComboBox = TryCast(DataGridCellObj, ComboBox)
If cb IsNot Nothing Then
cb.Focus()
cb.IsDropDownOpen = True
End If
End If
End If
End If
End Sub
Public Shared Function FindParent(Of T As DependencyObject)(dependencyObject As DependencyObject) As T
Dim parent = VisualTreeHelper.GetParent(dependencyObject)
If parent Is Nothing Then
Return Nothing
End If
Dim parentT = TryCast(parent, T)
Return If(parentT, FindParent(Of T)(parent))
End Function
快速解釋:在datagrid負載上添加一個CellFocusedChangedHandler處理程序,並在該子文件中追蹤該行內的對象是否爲文本框(在我的情況下)並設置它的焦點!
它爲我工作!
來源
2013-10-22 09:37:52
Rui