The tree is built with no problems if I use XAML to build one at design-time, but I am not sure how to do this for a dynamic case.
First of all, "XAML" and "dynamic" are not mutually exclusive. Are you absolutely sure you need build the grid and access CellStyles through procedural (VB) code? There are multiple options from XAML that are easier, more maintainable, and more dynamic than explicitly scanning the visual tree. For example:
Declare DataTemplates per column with DataGridTemplateColumn
Use DataTriggers in a DataGrid.CellStyle, DataGridColumn.CellStyle, or DataGrid.RowStyle
Define alternating / cycling row styles as described at AlternationCount
As for why you can't see items in the visual tree: When are you trying to access it? It won't populate instantly. You may need to wait for the Loaded
event, or the StatusChanged
event of the DataGrid's ItemContainerGenerator.