paragraph - [UWP][C#] 向 RichTextBlock 添加文本

标签 paragraph richtextblock

首先,我对 XAML 和 C# 都是全新的,所以请原谅我的一些愚蠢错误。非常感谢您的解释。

最近几个小时我一直在苦苦思索,试图找出最简单的事情之一:如何在按下按钮时向 RichTextBlock 添加文本。我尝试了一些在 Internet 上找到的解决方案,但没有一个真正有效。

特别是似乎没有必要的引用资料。例如 VS 无法识别以下代码:Run myrun = new Run();Paragraph mypar = new Paragraph();myrichtextblock.document.

我错过了什么?

最佳答案

检查这个例子:

摘自 MSDN 文档

https://msdn.microsoft.com/library/windows/apps/br227565

// Create a RichTextBlock, a Paragraph and a Run.
RichTextBlock richTextBlock = new RichTextBlock();
Paragraph paragraph = new Paragraph();
Run run = new Run();

// Customize some properties on the RichTextBlock.
richTextBlock.IsTextSelectionEnabled = true;
richTextBlock.TextWrapping = TextWrapping.Wrap;
run.Text = "This is some sample text to show the wrapping behavior.";
richTextBlock.Width = 200;

// Add the Run to the Paragraph, the Paragraph to the RichTextBlock.
paragraph.Inlines.Add(run);
richTextBlock.Blocks.Add(paragraph);

// Add the RichTextBlock to the visual tree (assumes stackPanel is decalred in XAML).
stackPanel.Children.Add(richTextBlock);

看看如何在这个例子中添加文本并修改代码以放入按钮的点击事件中

如果对您有用,请标记此答案!

最好的问候!

关于paragraph - [UWP][C#] 向 RichTextBlock 添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35710355/

相关文章:

html - 段落重叠图像

c# - 如何更改自定义跨度的背景颜色?

c# - 在 metro 应用程序的 RichTextBlock 中加载 HTMl

wpf - 如何删除空段落所占用的空间?

Vim - 如何跳转到段落的开头/结尾(适用于所有情况)

javascript - 通过 JavaScript 或 jQuery 删除内部带有不间断空格的 P 标签

html - 需要距电池顶部的空间

xaml - 自动检测 TextBlock 中的 URL、电话号码、电子邮件

windows-store-apps - RichTextBlockOverflow.HasOverflowContent 在 Windows 8 Metro 应用程序中始终为 false