文本框不允许垂直对齐到中心 [英] Textbox is not allowing vertical alignment to center

查看:116
本文介绍了文本框不允许垂直对齐到中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,想要将垂直对齐应用为中心,以便垂直居中对齐文本,但似乎无法使用垂直对齐/垂直对齐来实现此目的。我甚至试图为此提供填充但没有运气。


任何人都可以建议我如何在文本框中将文本垂直对齐。




Sachin Mehndiratta

解决方案

嗨Sachin Mehndiratta,


如果你在文本框中设置height属性,请将其删除。


此外,您还可以通过填充和VerticalContentAlignment进行垂直对齐,如下所示:

< Grid> 
< Grid.RowDefinitions>
< RowDefinition>< / RowDefinition>
< RowDefinition Height =" auto">< / RowDefinition>
< RowDefinition Height =" auto">< / RowDefinition>
< RowDefinition Height =" auto">< / RowDefinition>
< /Grid.RowDefinitions>
< TextBox Grid.Row =" 1" Grid.Column = QUOT 1 QUOT;高度= QUOT; 50"了borderThickness = QUOT 1 QUOT; BorderBrush = QUOT;#FFD5D5D5"字号= QUOT; 36英寸;文本= QUOT;试验" VerticalContentAlignment = QUOT;中心"填充= QUOT; 0" />
< TextBox Grid.Row =" 3" Grid.Column = QUOT 1 QUOT;高度= QUOT; 60"了borderThickness = QUOT 1 QUOT; BorderBrush = QUOT;#FFD5D5D5"字号= QUOT; 36英寸;文本= QUOT; TEST2" VerticalContentAlignment = QUOT;中心"填充= QUOT; 0" />

< / Grid>






祝你好运,


张龙


I have a textbox and want to apply vertical alignment as center so as to center align the text vertically but seems like I can not achieve this using vertical alignment/verticalcontentalignment. I have even tried to provide padding for this but no luck.

Can anyone suggest how can I center align my text vertically in a textbox.


Sachin Mehndiratta

解决方案

Hi Sachin Mehndiratta,

If you set the height property in your textbox, please remove it.

In addition, you could also allow vertical alignment via padding and VerticalContentAlignment, like this:

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="auto"></RowDefinition>
            <RowDefinition Height="auto"></RowDefinition>
            <RowDefinition Height="auto"></RowDefinition>
        </Grid.RowDefinitions>
        <TextBox Grid.Row="1" Grid.Column="1" Height="50" BorderThickness="1" BorderBrush="#FFD5D5D5" FontSize="36" Text="test" VerticalContentAlignment="Center" Padding="0" />
        <TextBox Grid.Row="3" Grid.Column="1" Height="60" BorderThickness="1" BorderBrush="#FFD5D5D5" FontSize="36" Text="test2" VerticalContentAlignment="Center" Padding="0" />

    </Grid>


Best regards,

Zhanglong


这篇关于文本框不允许垂直对齐到中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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