如何设置TextBlock中的制表符宽度?

问题描述 投票:0回答:1

我想减少

TextBlock
中制表符的宽度。制表符相当于大约 8 个字符。我想减少到大约 4 个空格。

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

我所看到的:

Some text  
        Line with tab.  
        Another line  

我想要什么:

Some text  
    Line with tab.  
    Another line  
c# wpf textblock
1个回答
1
投票

如何将每次出现的

\t
替换为四个(或您选择的数字)
spaces

这种方法可以通过修改代码来实现

textBlock.Text =  textBlock.Text.Replace("\t", "    ");
© www.soinside.com 2019 - 2024. All rights reserved.