WPF: Naming controls generated during binding for UI Automation Tests-Collection of common programming errors

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. TestComplete 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.