How to horizontally center inline (Run) versus other inline in WPF
I have TextBlock
in which I put 2 Inline
( Run
s), HorizontalAlignment
for the TextBlock is set to Center, that's ok, I just want to focus the first run versus 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:
What I want to achieve:
I tried looking for documentation and threads on the internet, but I didn't really find a way to achieve this, how can I figure this out?
+3
source to share
1 answer
Install TextAlignment="Center"
in your text block
<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>
+8
source to share