silverlight NaN 高度和宽度,ActualHeight 和 ActualWidth 也返回 0.0 - 解决方法是什么?

发布于 2024-10-01 06:08:59 字数 1045 浏览 1 评论 0原文

下面的 popUpControllistBoxControl 返回 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长发绾君心 2024-10-08 06:08:59

要更新 FrameworkElement 的 ActualWidthActualHeight,您必须调用 UpdateLayout

希望这对某人有帮助。

To update the ActualWidth and ActualHeight of a FrameworkElement you will have to call UpdateLayout.

hope this helps someone.

笑叹一世浮沉 2024-10-08 06:08:59

在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文