How to set the tab character width in a TextBlock?

67 Views Asked by At

I want to reduce the width of the tab character in a TextBlock. The tabs are the equivalent of about 8 characters. I want to reduce to approximately 4 spaces.

    TextBlock textBlock = new TextBlock 
    { 
        Text = "Some text\r\n\tLine with tab.\r\n\tAnother line",
    };

What I see:

Some text  
        Line with tab.  
        Another line  

What I want:

Some text  
    Line with tab.  
    Another line  
1

There are 1 best solutions below

0
Darshan Faldu On

How about replacing each occurrence of \t with four (or a number of your choice) spaces?

This approach could be implemented by modifying the code to

textBlock.Text =  textBlock.Text.Replace("\t", "    ");