これはうまく動作するかどうかわかりませんが、私のViewModelのすべての未処理のキーストロークを処理する必要があるので、未処理のキーストロークをViewModelに返します。MVVM ViewModel上で処理されていないすべてのキーストロークを処理する
しかし、問題はどのように処理されていないキーをすべて取得するかです。ここで
はちょうど彼らに
Public Class ForwardKeyBehavior
Inherits Behavior(Of DependencyObject)
Protected Overrides Sub OnAttached()
Keyboard.AddKeyDownHandler(Me.AssociatedObject, AddressOf OnKeyPressed)
Keyboard.AddPreviewKeyDownHandler(Me.AssociatedObject, AddressOf OnPreviewKeyPressed)
MyBase.OnAttached()
End Sub
Protected Overrides Sub OnDetaching()
Keyboard.RemoveKeyDownHandler(Me.AssociatedObject, AddressOf OnKeyPressed)
MyBase.OnDetaching()
End Sub
Private Sub OnPreviewKeyPressed(ByVal sender As Object, ByVal e As KeyEventArgs)
End Sub
Private Sub OnKeyPressed(ByVal sender As Object, ByVal e As KeyEventArgs)
If (Not e.Handled) Then
Trace.Write(e.Key.ToString())
End If
End Sub
End Class
をキャッチする私の最初の試みである。しかし、e.Handledはいつも、私はテキストボックスでキーを押してもを何をしないのです偽であると思われますか?
他のハンドルでe.HandledをTrueに設定する必要があります。それは自動ではありません。 –
キーがテキストボックスで扱われても? – Peter