/// <summary>
        /// Populate siblings
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="poiNode"></param>
        /// <param name="startId"></param>
        private int PopulateSiblingTreeNodes(A11yElement parentNode, A11yElement poiNode)
        {
            int childId = 1;

            IUIAutomationTreeWalker walker = this.TreeWalker;
            IUIAutomationElement    child  = null;

            if ((IUIAutomationElement)parentNode.PlatformObject != null)
            {
                try
                {
                    child = walker.GetFirstChildElement((IUIAutomationElement)parentNode.PlatformObject);
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception ex)
                {
                    ex.ReportException();
                    child = null;
                    System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex);
                }
#pragma warning restore CA1031 // Do not catch general exception types

                while (child != null)
                {
#pragma warning disable CA2000 // Use recommended dispose patterns
                    var childNode = new DesktopElement(child, true, false);
#pragma warning restore CA2000 // Use recommended dispose patterns
                    childNode.PopulateMinimumPropertiesForSelection();

                    if (childNode.IsSameUIElement(poiNode) == false)
                    {
                        childNode.UniqueId       = childId++;
                        childNode.Parent         = parentNode;
                        childNode.TreeWalkerMode = this.TreeWalkerMode;
                        this.Items.Add(childNode);
                    }
                    else
                    {
                        childNode = poiNode as DesktopElement;
                    }

                    parentNode.Children.Add(childNode);

                    try
                    {
                        child = walker.GetNextSiblingElement(child);
                    }
#pragma warning disable CA1031 // Do not catch general exception types
                    catch (Exception ex)
                    {
                        ex.ReportException();
                        child = null;
                        System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex);
                    }
#pragma warning restore CA1031 // Do not catch general exception types
                }
            }

            return(childId);
        }
Beispiel #2
0
        /// <summary>
        /// Populate siblings
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="poiNode"></param>
        /// <param name="startId"></param>
        private int PopulateSiblingTreeNodes(A11yElement parentNode, A11yElement poiNode)
        {
            int childId = 1;

            IUIAutomationTreeWalker walker = this.TreeWalker;
            IUIAutomationElement    child  = null;

            if ((IUIAutomationElement)parentNode.PlatformObject != null)
            {
                try
                {
                    child = walker.GetFirstChildElement((IUIAutomationElement)parentNode.PlatformObject);
                }
                catch (Exception ex)
                {
                    ex.ReportException();
                    child = null;
                    System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex);
                }

                while (child != null)
                {
                    var childNode = new DesktopElement(child, true, false);
                    childNode.PopulateMinimumPropertiesForSelection();

                    if (childNode.IsSameUIElement(poiNode) == false)
                    {
                        childNode.UniqueId       = childId++;
                        childNode.Parent         = parentNode;
                        childNode.TreeWalkerMode = this.TreeWalkerMode;
                        this.Items.Add(childNode);
                    }
                    else
                    {
                        childNode = poiNode as DesktopElement;
                    }

                    parentNode.Children.Add(childNode);

                    try
                    {
                        child = walker.GetNextSiblingElement(child);
                    }
                    catch (Exception ex)
                    {
                        ex.ReportException();
                        child = null;
                        System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex);
                    }
                }
            }

            return(childId);
        }