wpfsilverlightxamlactualwidthactualheight

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


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>

Solution

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

    hope this helps someone.