Pobieranie pełnej zawartości siatki danych za pomocą UIAutomation

Muszę pobrać wszystkie elementy w Datagrid z zewnętrznej aplikacji za pomocą UIAutomation. Obecnie mogę tylko pobierać (i wyświetlać w UISpy) widoczne elementy. Czy istnieje sposób na buforowanie wszystkich elementów w Datagrid, a następnie wyciągnięcie ich? Oto kod:

static public ObservableCollection<Login> GetLogins()
    {

        ObservableCollection<Login> returnLogins = new ObservableCollection<Login>();

        var id = System.Diagnostics.Process.GetProcessesByName("<Name here>")[0].Id;
        var desktop = AutomationElement.RootElement;

        var bw = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ProcessIdProperty, id));

        var datagrid = bw.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "lv"));

        var loginLines = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem));

        foreach (AutomationElement loginLine in loginLines)
        {
            var loginInstance = new Login { IP = new IP() };

            var loginLinesDetails = loginLine.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));

            for (var i = 0; i < loginLinesDetails.Count; i++)
            {
                var cacheRequest = new CacheRequest 
                { 
                    AutomationElementMode = AutomationElementMode.None,
                    TreeFilter = Automation.RawViewCondition
                };

                cacheRequest.Add(AutomationElement.NameProperty);
                cacheRequest.Add(AutomationElement.AutomationIdProperty);

                cacheRequest.Push();

                var targetText = loginLinesDetails[i].FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "TextBlock"));

                cacheRequest.Pop();

                var myString = targetText.Cached.Name;

                #region Determine data and write to return object
                //Removed private information
                #endregion
                }

            }

            returnLogins.Add(loginInstance);
        }

        return returnLogins;
    }

questionAnswers(2)

yourAnswerToTheQuestion