TextBlock 的默认高度是多少? [英] What is the default Height of a TextBlock?

查看:37
本文介绍了TextBlock 的默认高度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Silverlight 和 WPF 中,TextBlock 是否有默认高度?如果有,它是什么?

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

推荐答案

<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>

鉴于上述 XAML,对于 Silverlight 4,TextBlock 的默认字体大小为 11,ActualHeight 为 16.由于高度计算太晚,显示的 ActualHight 本身将为 0.

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.

有趣的是,WPF 中的 XAML 完全相同,TextBlock 的高度填充了它所在的容器.在这种情况下(无论如何对我来说)它显示自己的 ActualHeight 是 310.WPF 没有 Silverlight 绑定的问题到它自己的实际高度.调整窗口大小改变了高度.所以在这种情况下,默认高度可以说是它的 Auto(或 NaN).

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).

这篇关于TextBlock 的默认高度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆