What is the default Height of a TextBlock?

前端 未结 3 1026
醉梦人生
醉梦人生 2021-01-21 08:07

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

相关标签:
3条回答
  • 2021-01-21 08:24

    it is 23 in VS2008. But that is not so difficult to find out...

    0 讨论(0)
  • 2021-01-21 08:24

    It is not a true control but a frameworkelement. Hence it's default height is the same as the control within which it is kept.

    0 讨论(0)
  • 2021-01-21 08:31
    <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).

    0 讨论(0)
提交回复
热议问题