开发者

Formatting Richtextbox in WPF

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 Differen开发者_如何学Pythont Color.

Plz Tell me the Way Out


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");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜