Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to horizontally center an inline (Run) comparing to other inlines in WPF

I have TextBlock in which I put 2 Inlines (Runs), the HorizontalAlignment of the TextBlock is set to Center, this is ok, I just want to center the first Run comparing to the second, here's my code :

<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="/Throne;component/Fonts/#Segoe UI Light" FontSize="35" FontWeight="Bold" Visibility="{Binding UserNameTextBlockVisibility}">
    <Run FontSize="25">En tant que :</Run>
    <LineBreak />
    <Run Text="{Binding UserName}" Foreground="ForestGreen"/>
</TextBlock>

Here's the result I get :

enter image description here

What I want to achieve :

enter image description here

I tried to search around the documentation and in threads on the internet, but I didn't really find a way to achieve this, how can I realize that ?

like image 632
AymenDaoudi Avatar asked Nov 10 '14 11:11

AymenDaoudi


1 Answers

Set TextAlignment="Center" on your TextBlock

 <TextBlock TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="/Throne;component/Fonts/#Segoe UI Light" FontSize="35" FontWeight="Bold" Visibility="{Binding UserNameTextBlockVisibility}">
    <Run FontSize="25">En tant que :</Run>
    <LineBreak />
    <Run Text="{Binding UserName}" Foreground="ForestGreen"/>
</TextBlock>
like image 196
Nitin Avatar answered Oct 19 '22 21:10

Nitin