To reproduce:
Add a RadTextBoxControl to a form, insert a text using the following line:
this.radTextBoxControl1.AppendText(string.Format("{0} Foo {0} bar {0}", Environment.NewLine));
You will notice that the newlines are not taken into consideration
Workaround:
Use the following classes -
public class MyTextBoxControl : RadTextBoxControl
{
protected override RadTextBoxControlElement CreateTextBoxElement()
{
return new MyTextBoxControlElement();
}
}
public class MyTextBoxControlElement : RadTextBoxControlElement
{
protected override TextBoxViewElement CreateViewElement()
{
return new MyTextBoxViewElement();
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(RadTextBoxControlElement);
}
}
}
public class MyTextBoxViewElement : TextBoxViewElement
{
protected override void ReplaceTextBlock(ITextBlock targetBlock, int startCharPosition, int endCharPosition, string text)
{
if (string.IsNullOrEmpty(text) && startCharPosition == 0 && endCharPosition == targetBlock.Length)
{
this.Children.Remove(targetBlock as RadElement);
return;
}
string headText = targetBlock.Text.Substring(0, startCharPosition);
string tailText = targetBlock.Text.Substring(endCharPosition);
targetBlock.Text = headText;
if (TextBoxViewElement.IsSpecialText(text) || this.ContainsNewLine(text))
{
int index = string.IsNullOrEmpty(headText) ? targetBlock.Index : targetBlock.Index + 1;
index = this.InsertTextBlocks(index, text, TextBlockElementType);
if (string.IsNullOrEmpty(headText))
{
targetBlock.Index = index + 1;
}
if (!string.IsNullOrEmpty(headText) && !string.IsNullOrEmpty(tailText))
{
index = this.InsertTextBlocks(index + 1, tailText, TextBlockElementType);
return;
}
}
else
{
targetBlock.Text += text;
}
targetBlock.Text += tailText;
}
public bool ContainsNewLine(string text)
{
string[] words = text.Split(new char[] { ' ', ',', '.', '!', '?' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < words.Length; i++)
{
string word = words[i];
if (!string.IsNullOrEmpty(word) && word == Environment.NewLine)
{
return true;
}
}
return false;
}
}