Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add space to the end of a TextBlock in XAML? (Windows 10, UWP)

Text="Some text:" I want to add a space after the colon.

I've tried xml:space="preserve" and   but neither seems to work.

I know it can be done by adding margin, but I'm curious if there's another way.

like image 540
Viktor Simkó Avatar asked Dec 04 '22 02:12

Viktor Simkó


2 Answers

Try this, it works for me.

<RelativePanel>
    <TextBlock x:Name="test1" RelativePanel.Below="edLongitude">
        ahoj &#160;  
    </TextBlock>
    <TextBlock x:Name="test2" RelativePanel.Below="edLongitude" RelativePanel.RightOf="test1" Text="nazdar" />
</RelativePanel>
like image 85
Ive Avatar answered Feb 07 '23 00:02

Ive


Another alternative is using Run:

<TextBlock Foreground="Black">
    <Run Text="SomeText:"/>
    <Run/>
</TextBlock>

The Run element on a new line will add the space, but if you write the two Runs on the same line, the space will not be created:

<TextBlock Foreground="Black">
    <Run Text="SomeText:"/><Run/>
</TextBlock>
like image 30
Kristian Vukusic Avatar answered Feb 07 '23 00:02

Kristian Vukusic