Why is my Grid's width NaN? Why is my Grid's width NaN? wpf wpf

Why is my Grid's width NaN?


Does Stretch make the grid stretch to accomodate all its content, or to fill its container?

From MSDN about HorizontalAlignment="Stretch":

Child elements are stretched to fill the parent element's allocated layout space. Explicit Width and Height values take precedence.


Why is my Grid's width NaN?

NaN is to mean "not set". FrameworkElement is the base class for many Controls in WPF and if you do not explicitly set the Height and Width properties then in the class constructor will be a default value of NaN.


When I get WindowContainer.Width during start-up code for the view, it returns NaN

In this case try get the ActualWidth, instead of Width, because:

ActualWidth property is a calculated value based on other width inputs, and the layout system. The value is set by the layout system itself, based on an actual rendering pass, and may therefore lag slightly behind the set value of properties such as Width that are the basis of the input change.