programmatic textblock entry with linebreaks

前端 未结 5 1960
挽巷
挽巷 2020-12-20 12:41

How do I programmatically add text with line breaks to a textblock?

If I insert text like this:

helpBlock.Text = \"Here is some text. 

        
5条回答
  •  暖寄归人
    2020-12-20 12:57

    You could convert \n to programmatically.

        string text = "This is a line.\nThis is another line.";
        IList lines = text.Split(new string[] { @"\n" }, StringSplitOptions.None);
    
        TextBlock tb = new TextBlock();
        foreach (string line in lines)
        {
            tb.Inlines.Add(line);
            tb.Inlines.Add(new LineBreak());
        }
    

提交回复
热议问题