简体   繁体   English

WPF允许用户使用粗体/斜体/下划线等格式设置TextBlock

[英]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. 最好使用类似于Word的方法,在该方法中,他们可以选择文本,然后单击一个按钮,但我可以允许他们也将标签放在其中,例如<b> </ b>,只要格式正确即可。 。

Is there an easy way to do this using Inlines at runtime? 有没有一种简单的方法可以在运行时使用Inlines来做到这一点?

I definitely recommend you having a look at RichTextBox : 我绝对建议您看看RichTextBox

The RichTextBox control enables you to display or edit flow content including paragraphs, images, tables, and more. RichTextBox控件使您可以显示或编辑流内容,包括段落,图像,表格等。 This topic introduces the TextBox class and provides examples of how to use it in both Extensible Application Markup Language (XAML) and C#. 本主题介绍TextBox类,并提供有关如何在可扩展应用程序标记语言(XAML)和C#中使用它的示例。 ( Microsoft docs ) Microsoft文档

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... : 这是使用RichTextBox创建文本编辑器的非常深入的教程,使用按钮允许用户更改诸如字体大小,粗体,颜色等属性:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM