tags:

views:

46

answers:

1

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?

A: 

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.

HTH, Kent

Kent Boogaart
Thanks Kent - I did take a look but in all cases the object was being instantiated correctly in the g.cs files.I imagine this is a bug and just wondered if anyone else has come across it. It seems to affect the last declared XAML elements in my case.
sturdytree