如何在windows phone应用程序中获得richtextbox文本到textblock
本文关键字:richtextbox 文本 textblock windows phone 应用程序 | 更新日期: 2023-09-27 18:12:04
如何在windows phone应用程序中使用c#将richtextbox文本转换为textblock
我为windows phone应用程序做了这个
private void OnMessageReceived(string message)
{
var paragraph = new Paragraph();
var runs = new List<Inline>();
foreach (var word in message.Split(' '))
{
Uri uri;
if (Uri.TryCreate(word, UriKind.Absolute, out uri) ||
(word.StartsWith("www.") || word.EndsWith(".com") || word.Contains("@") && Uri.TryCreate("http://" + word, UriKind.Absolute, out uri)))
{
var link = new Hyperlink();
link.Inlines.Add(new Run() { Text = word });
link.Click += (sender, e) =>
{
var hyperLink = (sender as Hyperlink);
new WebBrowserTask() { Uri = uri }.Show();
};
runs.Add(link);
}
else
{
runs.Add(new Run() { Text = word });
}
runs.Add(new Run() { Text = " " });
}
foreach (var run in runs)
paragraph.Inlines.Add(run);
txtDisplayText.Blocks.Add(paragraph);
}
"txtDiplayText"是一个RichTextBox我想要的RichTextBox数据TextBlock
enter code here
您可以按如下方式创建RichTextBox
:
RichTextBox rtb = new RichTextBox();
rtb.TextWrapping = TextWrapping.Wrap;
rtb.FontSize = 12;
rtb.FontFamily = new FontFamily("Arial");
rtb.Width = this.Width;
Run run = new Run();
run.Text = "Hello World.Hello World.Hello World.Hello World.Hello World.";
Paragraph para = new Paragraph();
para.Inlines.Add(run);
rtb.Blocks.Add(para);
然后给控件一个名称,并将其添加到您想要的textblock
。
希望有帮助!