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

查看:119
本文介绍了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>

上面的代码给了我这个

垂直未对齐的Label和TextBlock文本http://img156.imageshack.us/img156/4940/labeltextblock.png

推荐答案

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

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天全站免登陆