1
以下是我控制視圖中檢查的工具,我想從文本塊中的樹下返回值:UIAutomation不會返回兒童元素的值
在我的WPF應用程序的窗口,一個數據網格有行和列,並試圖獲取特定行和列的文本值。第一行將文本值(timestamp)作爲子樹下的文本塊。
檢查控件的屬性是:
數據網格 - Datagrid的
日誌 - DataItemControlType
項目 - UIA_CustomControlType(DataGridCell)
自定義 - UIA_CustomControlType(DataGridCell)
文本 - UIA_TextControlTypeID
我可以得到總的行數,但無法獲得文本值。
var gridChilds = grid.LowLevelAutomationObject.FindAll(System.Windows.Automation.TreeScope.Children, Condition.TrueCondition).OfType<AutomationElement>();
var rows = gridChilds.Count() ;
List<AutomationElement> messages = new List<AutomationElement>();
TreeWalker walker = new TreeWalker(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem));
AutomationElement ae = grdControl as AutomationElement;
AutomationElement row = walker.GetFirstChild(ae);
messages.Add(row);
row = walker.GetNextSibling(row);
string result = Convert.ToString(row);
return result ;
我嘗試了一些解決方案,從類似的問題在線幫助,但沒有工作了我的例子。我是C#編程和工具的新手,所以任何幫助將不勝感激。
Max Young,非常感謝,我能夠得到一個類似於您提供的上述解決方案的工作。一些「很高興有」是在自定義級別循環並基於我給出的行號,它應該得到文本值。但是,非常感謝您的時間:) – cherryS
如果您需要UI Automation的任何幫助,請隨時給我發消息,沒問題。用可用資源學習UI自動化是非常可怕的。 –
當然,非常感謝您提供幫助。 – cherryS