You can create your own custom context menu to override the default one. The context menu allows the user to cut, copy, or paste (see illustration below). See Enable Spell Checking in a Text Editing Control to learn how to enable spellchecking.īy default, both TextBox and RichTextBox have a context menu that appears when a user right-clicks inside the control. When spellchecking is turned on, a red line appears underneath any misspelled words (see picture below). You can enable real-time spell checking in a TextBox or RichTextBox. Also, built in features like search, viewing mode, page navigation, and zoom are not available within a RichTextBox. For example, there are no columns in a RichTextBox and hence no automatic resizing behavior. To learn more about the features of flow content and how to work with it, see Flow Document Overview.įlow content inside a RichTextBox does not behave exactly like flow content contained in other controls. As a user edits RichTextBox content, they change this flow content. The following illustration shows how this sample renders.Įlements like Paragraph and Bold determine how the content inside a RichTextBox appears. ' Add initial content to the RichTextBox. ' Create a paragraph and add the Run and Bold to it. ' Create a Run of plain text and some bold text.ĭim myRun As New Run("This is flow content and you can ")ĭim myBold As New Bold(New Run("edit me!")) ' Create a FlowDocument to contain content for the RichTextBox. Partial Public Class BasicRichTextBoxWithContentExample Add initial content to the RichTextBox. RichTextBox myRichTextBox = new RichTextBox() Add the paragraph to the FlowDocument. Create a paragraph and add the Run and Bold to it. Run myRun = new Run("This is flow content and you can ") īold myBold = new Bold(new Run("edit me!")) Create a Run of plain text and some bold text. Create a FlowDocument to contain content for the RichTextBox.įlowDocument myFlowDoc = new FlowDocument() StackPanel myStackPanel = new StackPanel() Public BasicRichTextBoxWithContentExample() Public partial class BasicRichTextBoxWithContentExample : Page This is flow content and you can edit me! To demonstrate flow content in a RichTextBox, the following code shows how to create a RichTextBox with a paragraph and some bolded text. In order to contain flow content, a RichTextBox hosts a FlowDocument object which in turn contains the editable content. See Flow Document Overview for in depth information on flow documents. Flow content can contain many types of elements including formatted text, images, lists, and tables. Specifically, the content edited in a RichTextBox is flow content. The code below shows how to create a RichTextBox that a user can edit rich content in. The features from the table above are covered in more detail later. Controlįormatting commands like ToggleBold (Ctr+B)įlowDocument content like images, paragraphs, tables, etc.Īlthough TextBox does not support formatting related commands like ToggleBold (Ctr+B), many basic commands are supported by both controls such as MoveToLineEnd. The table below summarizes the main features of TextBox and RichTextBox. See TextBox Overview for more information on TextBox. A TextBox requires less system resources than a RichTextBox and it is ideal when only plain text needs to be edited (i.e. For example, editing a document, article, or blog that requires formatting, images, etc is best accomplished using a RichTextBox. A RichTextBox is a better choice when it is necessary for the user to edit formatted text, images, tables, or other rich content. This topic introduces the TextBox class and provides examples of how to use it in both Extensible Application Markup Language (XAML) and C#.īoth RichTextBox and TextBox allow users to edit text, however, the two controls are used in different scenarios. The RichTextBox control enables you to display or edit flow content including paragraphs, images, tables, and more.
0 Comments
Leave a Reply. |