Crazy About Run tag in WPF

We have some scenarios to have the content inside brackets but without space between open bracket with content and closed bracket with content.

We usually do like below,

  1. <TextBlock x:Name="SampleTextBlock1" Height="25" Width="200" HorizontalAlignment="Center"  
  2.    VerticalAlignment="Top" Margin="15">  
  3.    <Run Text="("/>  
  4.    <Run Text="Sample Run Text with Space"/>  
  5.    <Run Text=")"/>  
  6. </TextBlock>  

The output will be ( Sample Run Text with Space ).

The spaces are there as we said above.

To remove that space, simply we need to alter the code like below.

  1. <TextBlock x:Name="SampleTextBlock2" Height="25" Width="200" HorizontalAlignment="Center"  
  2.    VerticalAlignment="Center" Margin="15">  
  3.    <Run Text="("/><Run Text="Sample Run Text without Space"/><Run Text=")"/>  
  4. </TextBlock>  

The output will be (Sample Run Text without Space).

Hope this simple and crazy tip helps you.

Ebook Download
View all
Learn
View all