Hi,
I have some text which has "\r\n" newline markers. I would like to have the newlines in a WPF textblock. I've tried replacing "\r\n" with "& # 13;" (without the spaces), which worked when I set the Text property in XAML, but doesn't seem to work when setting from the C# code-behind.
So...what's the standard way to convert "\r\n" to newlines in a WPF textblock?
Thx in advance!
[Edit] After getting replies here, this is how I'm assigning text with "\r\n" newlines to a WPF textblock. It works fine, but in terms of coding can anyone confirm that it's a reasonable way to go?
// assign the message, replacing "\r\n" with WPF line breaks
string[] splitter = new string[] { "\r\n" };
string[] splitMessage = message.Split(splitter, StringSplitOptions.None);
int numParagraphs = splitMessage.Count();
if (numParagraphs == 1)
{
this.Message.Text = message;
}
else
{
// add all but the last paragraph, with line breaks
for (int i = 0; i < splitMessage.Count() - 1; i++)
{
string paragraph = splitMessage[i];
this.Message.Inlines.Add(new Run(paragraph));
this.Message.Inlines.Add(new LineBreak());
}
// add the last paragraph with no line break
string lastParagraph = splitMessage[splitMessage.Count() - 1];
this.Message.Inlines.Add(new Run(lastParagraph));
}
[/Edit]