Search code examples
c#wpftextblock

WPF allowing users to format TextBlock with bold/italics/underlining, etc


I am creating a template where users will be able to type in text and would like to make it so they can format it. Preferably by methods similar to Word where they can select the text and then click a button, but I would be OK with allowing them to put the tags in there also, like < b > < / b>, etc as long as it formats properly.

Is there an easy way to do this using Inlines at runtime?


Solution

  • I definitely recommend you having a look at RichTextBox:

    The RichTextBox control enables you to display or edit flow content including paragraphs, images, tables, and more. This topic introduces the TextBox class and provides examples of how to use it in both Extensible Application Markup Language (XAML) and C#. (Microsoft docs)

    Here is a pretty indepth tutorial of using RichTextBox to create a text editor, using buttons allowing the user to changes properties such as font size, bold, colour, etc... :

    https://wpf-tutorial.com/rich-text-controls/how-to-creating-a-rich-text-editor/.