Since System.Windows.Controls.RichTextBox does not have a property for Text to determine its value, you can detect its value using the following
string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text;
Then you can change _Text and post a new line using the following
_Text = _Text.Replace("pc", "Personal Computer"); if (_Text != new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text) { new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = _Text; }
So it will look like
string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text; _Text = _Text.Replace("pc", "Personal Computer"); // Replace pc with Personal Computer if (_Text != new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text) { new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = _Text; // Change the current text to _Text }
Note Instead of using Text.Replace("pc", "Personal Computer"); you can declare a List<String> in which you save the characters and their replacements
Example:
List<string> _List = new List<string>(); private void richTextBox1_TextChanged(object sender, TextChangedEventArgs e) { string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text; for (int count = 0; count < _List.Count; count++) { string[] _Split = _List[count].Split(',');
Thanks,
Hope you find this helpful :)
source share