0

AutomationElement を使用して wpf コントロールにアクセスしようとしていますが、例外がスローされることがあります。以下はコードです:

if (automationElement.TryGetCurrentPattern(ValuePattern.Pattern, out pattern)) 
{
    ValuePattern valuePattern = pattern as ValuePattern; 
    valuePattern.SetValue(valueToBeSet); 
}

私はここまでやっています。これにより、MS.Win32.UnsafeNativeMethods でいくつかのメソッド呼び出しがトリガーされ、例外が発生します。

イベント ログからのスタック トレース:

Exception Messages: 
    Win32Exception      : The parameter is incorrect

Type         : System.ComponentModel.Win32Exception, System, Version=4.0.0.0, Culture=neutral
Message      : The parameter is incorrect
Source       : WindowsBase
NativeErrorCode: 87
ErrorCode    : -2147467259
TargetSite   : Int32 GetWindowText(System.Runtime.InteropServices.HandleRef, System.Text.StringBuilder, Int32)
Stack Trace  :    at MS.Win32.UnsafeNativeMethods.GetWindowText(HandleRef hWnd, StringBuilder lpString, Int32 nMaxCount)
        at System.Windows.Automation.Peers.WindowAutomationPeer.GetNameCore()
        at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
        at System.Windows.ContextLayoutManager.fireAutomationEvents()
        at System.Windows.ContextLayoutManager.UpdateLayout()
        at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
        at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
        at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
        at System.Windows.Media.MediaContext.AnimatedRenderMessageHandler(Object resizedCompositionTarget)
        at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
        at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

WPF コントロールは、標準の WPF コントロールです (カスタマイズなし)。このエラーの原因を特定できません。ウィンドウ ハンドル (GetWindowText のパラメーター) が間違っていると思いますが、これを確認する方法がわかりません。それ以外の場合は、教えてください。

4

0 に答える 0