开发者

silverlight NaN height and width, ActualHeight and ActualWidth also return 0.0 - what is the workaround?

开发者 https://www.devze.com 2023-01-24 03:16 出处:网络
popUpControl and listBoxControl below are returning NaN as the height and width. The ActualHeight is also 0.0

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 thi开发者_StackOverflow中文版s?

<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>


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

hope this helps someone.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消