silverlight NaN 高度和宽度,ActualHeight 和 ActualWidth 也返回 0.0 - 解决方法是什么?
下面的 popUpControl
和 listBoxControl
返回 NaN
作为高度和宽度。 ActualHeight
也是 0.0
为什么?更重要的是,解决方法是什么?
<Popup Name="popUpControl" IsOpen="True" VerticalAlignment="Top" HorizontalAlignment="Left" >
<ListBox Name="listBoxControl" SelectionChanged="_ListBox_SelectionChanged"
Style="{StaticResource ListBoxStyle}" BorderBrush="Transparent"
MaxHeight="300" MaxWidth="350" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding ID}" VerticalAlignment="Center" Margin="2,0,0,0" />
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" Margin="2,0,0,0" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Popup>
popUpControl
and listBoxControl
below are returning NaN
as the height and width. The ActualHeight
is also 0.0
Why? and more importantly what is the workaround for this?
<Popup Name="popUpControl" IsOpen="True" VerticalAlignment="Top" HorizontalAlignment="Left" >
<ListBox Name="listBoxControl" SelectionChanged="_ListBox_SelectionChanged"
Style="{StaticResource ListBoxStyle}" BorderBrush="Transparent"
MaxHeight="300" MaxWidth="350" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding ID}" VerticalAlignment="Center" Margin="2,0,0,0" />
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" Margin="2,0,0,0" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Popup>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要更新 FrameworkElement 的
ActualWidth
和ActualHeight
,您必须调用UpdateLayout
。希望这对某人有帮助。
To update the
ActualWidth
andActualHeight
of a FrameworkElement you will have to callUpdateLayout
.hope this helps someone.
在 WPF 和 silverlight 中,NaN 的宽度和/或高度表示“自动”,您可能应该查看(并绑定到)的内容是 ActualWidth 和/或 ActualHeight
in WPF and silverlight, a width and/or height of NaN means "Auto" what you should probably be looking at (and binding to) instead is ActualWidth and/or ActualHeight