2014-07-09 57 views
1

如何使用C#
我這樣做是爲Windows Phone應用程序,以獲取RichTextBox的文本在Windows Phone應用程序文本塊如何將richtextbox文本轉換爲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 

回答

0

您可以創建如下的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

希望它能幫助!

相關問題