1

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>
Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
VoodooChild
  • 9,776
  • 8
  • 66
  • 99
  • I can see the popup control with the listbox populated. I am checking for the height after I set the listBoxControls itemssource and after opening the popupcontrol. – VoodooChild Nov 08 '10 at 04:51

2 Answers2

5

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

hope this helps someone.

VoodooChild
  • 9,776
  • 8
  • 66
  • 99
-1

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

Muad'Dib
  • 28,542
  • 5
  • 55
  • 68