I have this rectangle
var rectangle = new Rectangle()
{
Width = double.NaN,
Height = 32,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
Fill = Brushes.WhiteSmoke
};
Which I add to the mainGrid of the window like this:
(mainWindow.Content as Grid).Children.Add(rectangle);
By doing this, the rectangle will not autofit to the grid width (it doesn't even appear), however if I add an amount, say 300 to its width, it will appear in the grid at the position I indicated.
What am I doing wrong?