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
精彩评论