当前位置: 首页>>代码示例>>C#>>正文


C# AutomationElement.SetCachedFirstChild方法代码示例

本文整理汇总了C#中System.Windows.Automation.AutomationElement.SetCachedFirstChild方法的典型用法代码示例。如果您正苦于以下问题:C# AutomationElement.SetCachedFirstChild方法的具体用法?C# AutomationElement.SetCachedFirstChild怎么用?C# AutomationElement.SetCachedFirstChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Automation.AutomationElement的用法示例。


在下文中一共展示了AutomationElement.SetCachedFirstChild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseTreeDescription

        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------
 
        #region Private Methods

        // Parses the string as returned from ElementSearcher - see ElementSearcher.cs
        // for a description of the format string. Summary is that it is a lisp-like
        // set of parens indicating tree structure (eg. "(()())" indicates a node containing
        // two child nodes), but uses 'P' instead of an open paran to indicate that the
        // corresonding node has a property array that needs to be associated with it.
        //
        // index is the current position in the tree strucure string,
        // propIndex is the current position in the array of property arrays
        // (an array of properties returned for each element that matches the
        // condition specified in the Searcher condition.)
        private static AutomationElement ParseTreeDescription( string treeDescription,
                                                               object[,] properties,
                                                               ref int index,
                                                               ref int propIndex,
                                                               UiaCoreApi.UiaCacheRequest cacheRequest,
                                                               bool askedForChildren,
                                                               bool askedForDescendants )
        {
            // Check that this is a 'begin node' tag (with or without properties)...
            if (string.IsNullOrEmpty(treeDescription))
                return null;
            char c = treeDescription[index];

            if (c != '(' && c != 'P')
            {
                return null;
            }

            bool havePropertiesForThisNode = c == 'P';

            index++;

            SafeNodeHandle hnode = null;

            // If we have information for this node, and we want full remote
            // references back, then extract the hnode from the first slot of that
            // element's property row...
            if (havePropertiesForThisNode && cacheRequest.AutomationElementMode == AutomationElementMode.Full)
            {
                hnode = (SafeNodeHandle)properties[propIndex, 0];
            }

            // Attach properties if present...
            object[,] cachedValues = null;
            int cachedValueIndex = 0;
            if (havePropertiesForThisNode)
            {
                cachedValues = properties;
                cachedValueIndex = propIndex;
                propIndex++;
            }

            AutomationElement node = new AutomationElement(hnode, cachedValues, cachedValueIndex, cacheRequest);

            if( askedForChildren || askedForDescendants )
            {
                // If we did request children or descendants at this level, then set the
                // cached first child to null - it may get overwritten with
                // an actual value later; but the key thing is that it gets
                // set so we can distinguish the "asked, but doesn't have one" from
                // the "didn't ask" case. (Internally, AutomationElement uses
                // 'this' to indicate the later case, and throws an exception if
                // you ask for the children without having previously asked
                // for them in a CacheRequest.)
                node.SetCachedFirstChild(null);
            }

            // Add in children...
            AutomationElement prevChild = null;

            for (; ; )
            {
                // Recursively parse the string...
                AutomationElement child = ParseTreeDescription( treeDescription, properties,
                                                                ref index, ref propIndex, cacheRequest,
                                                                askedForDescendants, askedForDescendants);

                if (child == null)
                    break;

                // Then link child node into tree...
                child.SetCachedParent(node);

                if (prevChild == null)
                {
                    node.SetCachedFirstChild(child);
                }
                else
                {
                    prevChild.SetCachedNextSibling(child);
                }

//.........这里部分代码省略.........
开发者ID:JianwenSun,项目名称:cc,代码行数:101,代码来源:CacheHelper.cs


注:本文中的System.Windows.Automation.AutomationElement.SetCachedFirstChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。