Jonathan Jenne 16a6febb34 jj
2019-08-09 17:12:34 +02:00

40 lines
1.3 KiB
VB.net

Imports System.Windows.Automation
Imports System.Windows.Automation.Automation
Imports DigitalData.Modules.Logging
Public Class ClassAutomation
Public Property AutomationId As String = String.Empty
Public Property FrameworkId As String = String.Empty
Private _focusHandler As AutomationFocusChangedEventHandler = Nothing
Private _LogConfig As LogConfig
Private _Logger As Logger
Public Sub New(LogConfig As LogConfig)
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger()
_focusHandler = New AutomationFocusChangedEventHandler(AddressOf OnFocusChange)
AddAutomationFocusChangedEventHandler(_focusHandler)
End Sub
Public Sub [RemoveHandler]()
If _focusHandler IsNot Nothing Then
RemoveAutomationFocusChangedEventHandler(_focusHandler)
End If
End Sub
Public Sub OnFocusChange(src As Object, e As AutomationFocusChangedEventArgs)
Try
Dim oElement As AutomationElement = src
If oElement IsNot Nothing AndAlso oElement IsNot Nothing Then
AutomationId = oElement.Current.AutomationId
FrameworkId = oElement.Current.FrameworkId
End If
Catch ex As Exception
Logger.Error(ex)
End Try
End Sub
End Class