none
Textbox is not allowing vertical alignment to center RRS feed

  • Question

  • 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

    Friday, April 20, 2018 3:02 AM

All replies

  • 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


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 20, 2018 8:08 AM
    Moderator