InvokePattern.Invoke 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
发送请求以激活控件并启动其单一、明确的操作。
public:
void Invoke();
public void Invoke ();
member this.Invoke : unit -> unit
Public Sub Invoke ()
例外
该元素不支持 InvokePattern 控件模式,或者被隐藏或被阻止。
元素未启用。 可在 UI 自动化提供程序已实现自己对 IsEnabled 属性的处理时引发。
示例
在下面的示例中,从 InvokePattern 控件获取控件模式并 Invoke 调用该方法。
///--------------------------------------------------------------------
/// <summary>
/// Obtains an InvokePattern control pattern from a control
/// and calls the InvokePattern.Invoke() method on the control.
/// </summary>
/// <param name="targetControl">
/// The control of interest.
/// </param>
///--------------------------------------------------------------------
private void InvokeControl(AutomationElement targetControl)
{
InvokePattern invokePattern = null;
try
{
invokePattern =
targetControl.GetCurrentPattern(InvokePattern.Pattern)
as InvokePattern;
}
catch (ElementNotEnabledException)
{
// Object is not enabled
return;
}
catch (InvalidOperationException)
{
// object doesn't support the InvokePattern control pattern
return;
}
invokePattern.Invoke();
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains an InvokePattern control pattern from a control
''' and calls the InvokePattern.Invoke() method on the control.
''' </summary>
''' <param name="targetControl">
''' The control of interest.
''' </param>
'''--------------------------------------------------------------------
Private Sub InvokeControl(ByVal targetControl As AutomationElement)
Dim invokePattern As InvokePattern = Nothing
Try
invokePattern = _
DirectCast(targetControl.GetCurrentPattern(invokePattern.Pattern), _
InvokePattern)
Catch e As ElementNotEnabledException
' Object is not enabled.
Return
Catch e As InvalidOperationException
' Object doesn't support the InvokePattern control pattern
Return
End Try
invokePattern.Invoke()
End Sub
注解
Invoke调用应立即返回而不阻止。 但是,此行为完全依赖于 Microsoft UI 自动化 提供程序实现。 在调用 Invoke 会导致阻塞问题 ((例如模式对话) 单独的帮助程序线程)调用该方法时,可能需要调用。