WPF 允许用户使用 bold/italics/underlining 等格式化 TextBlock

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

我正在创建一个模板,用户可以在其中输入文本并希望制作它以便他们可以对其进行格式化。最好通过类似于 Word 的方法,他们可以 select 文本,然后单击按钮,但我也可以允许他们也将标签放在那里,比如 < b > 等,只要因为格式正确。

有没有在运行时使用内联的简单方法?

我绝对推荐你看看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)

这是一个非常深入的教程,使用 RichTextBox 创建文本编辑器,使用允许用户更改字体大小、粗体、颜色等属性的按钮...:[=​​14= ]

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