在 XAML 中垂直对齐顶部的标签和文本块 [英] Vertically aligning Labels and TextBlocks at Top in XAML

查看:36
本文介绍了在 XAML 中垂直对齐顶部的标签和文本块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Top 处垂直对齐 LabelTextBlock 以使它们的第一行文本对齐?

How can I vertically align a Label and TextBlock at Top so that their first lines of text line up?

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
    </Grid.RowDefinitions>
    <Label Grid.Column="0" VerticalAlignment="Top">Some Label:</Label>
    <TextBlock Grid.Column="0" VerticalAlignment="Top">Some text<TextBlock>
</Grid>

上面的代码给了我这个:

The above code gives me this:

标签和文本块垂直未对齐 http://img156.imageshack.us/img156/4940/labeltextblock.png

推荐答案

标签周围的多余空间来自 Padding 属性.要移除空格,您可以直接在 Label 上显式地将 Padding 属性设置为0",当然,也可以通过 Style 进行设置.

The extra space around the label comes from the Padding property. To remove the space, you can explicitly set the Padding property to "0" directly on the Label, or, of course, set it via a Style.

这篇关于在 XAML 中垂直对齐顶部的标签和文本块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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