XAML RichTextBox Code Example

This article has move here: WPF RichTextBox Control Tutorial

The following code snippet creates RichTextBox in XAML.

  1. <RichTextBox></RichTextBox>  
The following code snippet sets the name, height and width of a RichTextBox control. The code also sets the horizontal alignment to left and the vertical alignment to top.
  1. <RichTextBox Margin="10,10,0,13" Name="RichTextBox1" HorizontalAlignment="Left"   
  2.                  VerticalAlignment="Top" Width="500" Height="300" />  
The following code snippet adds several items to a RichTextBox control.
  1. <RichTextBox Margin="10,10,0,13" Name="RichTextBox1" HorizontalAlignment="Left"   
  2.              VerticalAlignment="Top" Width="500" Height="300">  
  3.     <FlowDocument>  
  4.         <Paragraph>  
  5.             I am a flow document. Would you like to edit me?  
  6.             <Bold>Go ahead.</Bold>                  
  7.         </Paragraph>  
  8.         
  9.         <Paragraph Foreground="Blue">            
  10.             I am blue I am blue I am blue.    
  11.         </Paragraph>  
  12.     </FlowDocument>          
  13. </RichTextBox>  
A RichTextBox control comes with spell check functionality out-of-the-box. By setting the SpellCheck.IsEnabled property to true enables spell checking in a RichTextBox.
  1. SpellCheck.IsEnabled="True"  
You can set this in code as follows:
  1. mcRTB.SpellCheck.IsEnabled = true;  

Up Next
    Ebook Download
    View all
    Learn
    View all
    Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.