// Get the current caret position in the RichTextBox
TextPointer caretPosition = rtb.CaretPosition;
// Create a new Run with the typed text
Run run = new Run(e.Text);
// Apply formatting (bold) to the Run
run.FontWeight = FontWeights.Bold;
// Create a new TextRange from the caret position to the next insertion position
TextRange insertionRange = new TextRange(caretPosition, caretPosition);
// Set the text of the insertion range to the typed text
insertionRange.Text = e.Text;
// Apply formatting (bold) to the inserted text
insertionRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
// Move the caret position to the end of the inserted text
rtb.CaretPosition = insertionRange.End;
// Mark the event as handled to prevent the default insertion of the typed text
e.Handled = true;