I have a grid in a XAML file in a WPF project. This MainGrid contains 3 columns into which I have placed another 3 grids.
If I arrange the MainGrid children in order 0,1,2 in the XAML e.g.
<Grid Grid.Column="0" Name="grid0"></Grid>
<Grid Grid.Column="1" Name="grid1"></Grid>
<Grid Grid.Column ="2" Name="grid2"></Grid>
then the grid2 remains null at runtime (in the MainWindow_Loaded event).
However, if I rearrange the order in the XAML file as below, then everything is not null and it works fine.
<Grid Grid.Column="1" Name="grid1"></Grid>
<Grid Grid.Column="2" Name="grid2"></Grid>
<Grid Grid.Column ="0" Name="grid0"></Grid>
Copying the code to a new project cannot reproduce the problem, and so it must be something to do with a setting in my current project. Does anyone have any ideas where I should look to determine what is behind this?
You could look in the files generated for your .xaml files. These are the .g.cs files in your obj directory. Perhaps comparing the non-working .g.cs file to a working one will give you a clue as to what is going on.