silverlight NaN height and width, ActualHeight and ActualWidth also return 0.0 - what is the workaround?
-
29-09-2019 - |
Question
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.
OTHER TIPS
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow