Align Text to the center

Posted on 2011-10-25
Last Modified: 2012-05-12
Hello all,

I program with WPF. How can I align my Text to the center (Vertical)?


                     <DataGridTextColumn Binding="{Binding Path=MyName, Mode=OneWay}" Header="My Name" IsReadOnly="True" />                    
                     <DataGridTextColumn ....  />
                            <StackPanel Orientation="Horizontal">
                                <TextBlock HorizontalAlignment="Left"/>
                                <Button HorizontalAlignment="Right" VerticalAlignment="Bottom"/>

Thank you very much in advance. :)
Question by:chang2008
    LVL 17

    Expert Comment

    Have you tried ?

    LVL 17

    Accepted Solution

    If it not working the you need to something like this

    <TextBlock Height="22" Padding="3" />

    Author Comment


    Padding works already in TextBlock. It is in one of the column.

    but I have also the binding text in ...

    <DataGridTextColumn Binding="{Binding Path=MyName, Mode=OneWay}" Header="My Name" IsReadOnly="True" />

    How can I do padding in it?

    Author Comment

    I did like this in DataGridTextColumn and it works.

                        <Style TargetType="TextBlock">
                            <Setter Property="Padding" Value="5"/>
                            <Style TargetType="TextBox">
                                <Setter Property="Padding" Value="5"/>

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now