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).
精彩评论