开发者

WPF: Naming controls generated during binding for UI Automation Tests

开发者 https://www.devze.com 2023-02-19 09:25 出处:网络
Has anyone solved the problem of naming controls that are only generated at runtime? For example, I have a TreeView used to display a navigation menu. TestC开发者_如何学Pythonomplete supports recordi

Has anyone solved the problem of naming controls that are only generated at runtime?

For example, I have a TreeView used to display a navigation menu. TestC开发者_如何学Pythonomplete supports recording navigation using the TreeView, but since the ItemsSource is databound, they don't have names, so if a new item is added to the menu, the recorded tests are broken.

I'm looking at parsing the tree items in the Loaded event and setting names using RegisterName(), but between the visual and logical trees this seems quite difficult.


You should generally use the AutomationProperties attached properties and a TreeViewItem Style. Then you can bind say AutomationProperties.Name to an appropriate name from your view-model (or generated from).

0

精彩评论

暂无评论...
验证码 换一张
取 消