If you just set the value of the Text property in the TextBlock as β Example β (note that there are 3 spaces at the end of this line), which shows the TextBlock in the user interface is just β Example β.
And after searching for solutions on the Internet, I found that there is a way to solve this problem:
<Border BorderThickness="1" BorderBrush="#FFFF0202" HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBlock x:Name="t1"> <Run Text="Example   "/> </TextBlock> </Border>
The above code shows that using Inline Property TextBlock and   in Run Text displays spaces correctly.
However, I need to set the value of the TextBlock property to Code-behind (or via DataBinding) , the trick above does not work, and it shows Example    in the user interface.
I tried to set the value of the Run Text property by data binding, which, I think, can correctly display an escape character, but the Run Text property is NOT a dependent property, so I have no better way to solve this problem.
(However, I think that using the padding property for TextBlock is also a trick for this, and it should work. But is there a better way to do this?)
source share