Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Align Text to the center

Posted on 2011-10-25
4
Medium Priority
?
319 Views
Last Modified: 2012-05-12
Hello all,

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

myFile.xaml

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

Thank you very much in advance. :)
2011-10-25-124025.jpg
0
Comment
Question by:chang2008
  • 2
  • 2
4 Comments
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 37023648
Have you tried ?

VerticalAlignment="Center"
0
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 2000 total points
ID: 37023659
If it not working the you need to something like this

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

Author Comment

by:chang2008
ID: 37023781

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?
0
 

Author Comment

by:chang2008
ID: 37023935
I did like this in DataGridTextColumn and it works.

                    <DataGridTextColumn.ElementStyle>
                    <Style TargetType="TextBlock">
                        <Setter Property="Padding" Value="5"/>
                    </Style>
                    </DataGridTextColumn.ElementStyle>
                    <DataGridTextColumn.EditingElementStyle>
                        <Style TargetType="TextBox">
                            <Setter Property="Padding" Value="5"/>
                        </Style>
                    </DataGridTextColumn.EditingElementStyle>
                </DataGridTextColumn>  
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month21 days, 7 hours left to enroll

810 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