2

If some body HElp me regarding the Issue...

I have a Dynamic Fields comming from database.. These fields populated on RichTextBox after changing the color... Means Different Fields in Different Color.

Plz Tell me the Way Out

1 Answer 1

3

This should help get you started. It is an event handler that is wired to a 'Format code block' button. The handler shors how to get the selected text and apply basic formatting to it. If you want to work with all text in the box, then simply set the TextRange accordingly.

/// <summary>
/// Formats code blocks.
/// </summary>
private void OnCodeBlockClick(object sender, RoutedEventArgs e)
{
    var selection = TextBox.Selection;
    var textRange = new TextRange(selection.Start, selection.End);
    textRange.ApplyPropertyValue(TextElement.FontFamilyProperty, "Consolas");
    textRange.ApplyPropertyValue(TextElement.FontSizeProperty, 10D );
    textRange.ApplyPropertyValue(TextElement.BackgroundProperty, "LightSteelBlue");
}
Sign up to request clarification or add additional context in comments.

1 Comment

This is a great solution. Is there any way to remove tables from the TextRange using this method?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.