我在视图中具有以下标记。当我WindowContainer.Width
在视图的启动代码期间获得该代码时,它将返回NaN
。
<Border BorderThickness="10">
<StackPanel x:Name="Panel" Orientation="Vertical" >
<Grid x:Name="WindowContainer" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Loaded="WindowContainer_OnLoaded">
<delphi:Win32WindowHost x:Name="Host" />
</Grid>
<TextBlock x:Name="InfoTextBlock" HorizontalAlignment="Right" />
</StackPanel>
</Border>
是否Stretch
使网格拉伸以适应其所有内容或填充其容器?我希望它能拉伸以填充容器,Border
并具有适当的double
宽度,我可以使用该宽度将浮动窗口的大小设置为相同大小。
Does Stretch make the grid stretch to accomodate all its content, or to fill its container?
从MSDN
大约HorizontalAlignment="Stretch"
:
子元素被拉伸以填充父元素分配的布局空间。显式
Width
和Height
值优先。
Why is my Grid's width NaN?
NaN
表示“未设置”。FrameworkElement
是WPF中许多控件的基类,如果未显式设置Height和Width属性,则类构造函数中的默认值为NaN
。
When I get WindowContainer.Width during start-up code for the view, it returns NaN
在这种情况下,请尝试获取ActualWidth
而不是Width
,因为:
ActualWidth
属性是根据其他宽度输入和布局系统计算得出的值。该值是由布局系统本身根据实际渲染过程设置的,因此可能略微落后于作为输入更改基础的诸如Width之类的属性的设置值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句