wpfsilverlight

What is the default Height of a TextBlock?


In Silverlight and WPF, is there a default height for a TextBlock and if so, what is it?


Solution

  • <Grid x:Name="LayoutRoot" Background="White">
        <Border BorderBrush="Blue" BorderThickness="1" CornerRadius="5">
            <TextBlock x:Name="Itself" Text="{Binding ElementName=Itself, Path=ActualHeight}" />
        </Border>
    </Grid>
    

    Given the above XAML, with Silverlight 4, the TextBlock has a default fontsize of 11, and an ActualHeight of 16. The ActualHight shown in itself will be 0 due to the height being calculated too late.

    That's assuming you don't set them, in which case they won't be defaults.

    Interestingly, the exact same XAML in WPF, the height of the TextBlock fills the container it's in. In this case (for me anyway) it showed its own ActualHeight was 310. WPF didn't have the issue Silverlight had with binding to its own ActualHeight. Resizing the window changed the height. So in this case the default height could be said that its Auto (or NaN).