我是MVVM模式的新手,在我的应用程序中,当文本框的验证在该文本框失去焦点时出错时,焦点必须保持在同一文本本身,当我尝试实现时,设置焦点的方法和失去焦点的是反复呼唤。
设置焦点方法
Public Sub MainMenu_Focus(sender As Object, e As MainWindowEventArgs)
If TxtEditNDCClinicalScreen.IsEnabled Then
' TxtEditNDCClinicalScreen.Focus()
Keyboard.Focus(TxtEditNDCClinicalScreen)
If TxtEditNDCClinicalScreen.GetType() Is GetType(TextEdit) Then
CType(TxtEditNDCClinicalScreen, TextEdit).SelectAll()
End If
End If
End Sub
失去焦点的方法
Private Sub TxtEditNDCClinicalScreen_LostFocus(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles TxtEditNDCClinicalScreen.LostFocus
VM.CommandFind(TxtEditNDCClinicalScreen.Text.Length)
End Sub
我也尝试过互动触发器,但没有用..面临同样的问题。
<i:Interaction.Triggers>
<i:EventTrigger EventName="LostFocus">
<i:InvokeCommandAction Command="{Binding CommandLostFocus}" CommandParameter="{Binding Path=Text.Length,ElementName=TxtEditNDCClinicalScreen}" />
</i:EventTrigger> IsHitTestVisible="True"
</i:Interaction.Triggers>
请建议如何解决问题 感谢名单。