Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does my rectangle not appear in the grid?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What am I doing wrong?

>Solution :

You can’t set both Width = double.NaN and HorizontalAlignment = HorizontalAlignment.Center.

Either assign a value to Width and let HorizontalAlignment to be Center,
Or assign set HorizontalAlignment = HorizontalAlignment.Stretch and let Width to be NaN.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading