1

我为我的自定义控件编写了 AutomationPeer 类:

    // Automation Peer for the CustomControl
    private class CustommControlAutomationPeer : FrameworkElementAutomationPeer, IValueProvider, IGridProvider
    {
        public CustomControlAutomationPeer(CustomControl control)
            : base(control)
        { }

        #region overriding the "Core" methods from the base automation peer class that describe behavior unique and specific to custom control
         ...
        #endregion

        #region overriding of GetPattern should return the object that implements the specified pattern
        public override object GetPattern(PatternInterface patternInterface)
        {
            if (patternInterface == PatternInterface.Grid || patternInterface == PatternInterface.Value)
            {
                return this;
            }
            return base.GetPattern(patternInterface);
        }

        #endregion

        #region IGridProvider
         ...
        #endregion

        #region IValueProvider
         ...
        #endregion

        /// <summary>
        /// Pointer to CustomControl
        /// </summary>
        private CustomControl Control
        {
            get
            {
                return (CustonControl)base.Owner;
            }
        }
    }

在安装了 Visual Studio 的计算机和安装了测试代理的其他计算机上,我使用代码启动了 testmethod:

AutomationPattern[] supportedPatterns = customControl.GetSupportedPatterns();
        foreach (var supPattern in supportedPatterns)
            Trace.WriteLine(supPattern.ProgrammaticName);

结果跟踪:

在带有视觉工作室的计算机中:

QTAgent32.exe, <a class=success>Playback - {43} [SUCCESS] MouseButtonClick - "[UIA]ControlType='RadioButton' && AutomationId='allCriteriaRadioButton'"
\0</a>  
**ValuePatternIdentifiers.Pattern;  
GridPatternIdentifiers.Pattern**  
QTAgent32.exe, IEDOM : StopSession of the plugin called before StartSession
QTAgent32.exe, UIA : StopSession of the plugin called before StartSession

在带有测试代理的计算机中:

QTAgent32.exe, &lt;a class=success&gt;Playback - {43} [SUCCESS] MouseButtonClick - "[UIA]ControlType='RadioButton' &amp;&amp; AutomationId='allCriteriaRadioButton'"
\0&lt;/a&gt;  
**GridPatternIdentifiers.Pattern**  
 QTAgent32.exe, IEDOM : StopSession of the plugin called before StartSession
QTAgent32.exe, UIA : StopSession of the plugin called before StartSession

为什么在第二种情况下我只得到 IGridProvider?

4

0 回答 0