Odd Newline Behaviour in c# WPF

Viewed 50

I am migrating from Windows Forms in VB to WPF C# and I wrote the following code....

namespace TestWPF
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            OutputBox.Document.Blocks.Clear();
        }

        private void AcceptButton_Click(object sender, RoutedEventArgs e)
        {
            OutputBox.AppendText(String.Format("You clicked the button.{0}",Environment.NewLine));
        }
    }
}

Where OutputBox is a RichTextBox.

Upon running the program and clicking the button a few times I get output like the following....

You clicked the button.You clicked the button.

You clicked the button.

You clicked the button.

Why does the 1st newline not appear, and then it inserts blank lines rather than just moving on to the next line.

If I change the code to

.AppendText(String.format("You clicked the button.{0}OK{0}",environment.NewLine

I get output

You clicked the button.

OKYou clicked the button.

OK

You clicked the button.

OK

What should my code be like to get output....

You clicked the button.
You clicked the button.
You clicked the button.
1 Answers
Related