programmatic textblock entry with linebreaks

前端 未结 5 1966
挽巷
挽巷 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 13:08

    Solution:

    I would use "\n" instead of linebreaks. Best way would be use it on this way:

    Resources.resx file:

    myTextline: "Here is some text. \n Here is \n some \n more."
    

    In yours Class:

    helpBlock.Text = Resources.myTextline;
    

    This will looks like:

    Other solution would be to build your string here with Environment.NewLine.

    StringBuilder builder = new StringBuilder();
    builder.Append(Environment.NewLine);
    builder.Append(Resources.line1);
    builder.Append(Environment.NewLine);
    builder.Append(Resources.line2);
    helpBlock.Text += builder.ToString();
    

    Or use here "\n"

    StringBuilder builder = new StringBuilder();
    builder.Append("\n");
    builder.Append(Resources.line1);
    builder.Append("\n");
    builder.Append(Resources.line2);
    helpBlock.Text += builder.ToString();
    

提交回复
热议问题