Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7813671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:57:11+00:00 2026-06-02T04:57:11+00:00

When I try to set a textblock with rtf it gives a funny output

  • 0

When I try to set a textblock with rtf it gives a funny output is there a way to display rtf in a textblock if so how?

private void button1_Click(object sender, RoutedEventArgs e)
{
    TextRange tr = new TextRange(richTextBox1.Document.ContentStart,
                     richTextBox1.Document.ContentEnd);
    MemoryStream ms = new MemoryStream();
    tr.Save(ms, DataFormats.Rtf); 
    string rtfText = ASCIIEncoding.Default.GetString(ms.ToArray());
    textBlock1.Text = rtfText;

Edit update:

I can do this:

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        TextRange tr = new TextRange(richTextBox1.Document.ContentStart,
             richTextBox1.Document.ContentEnd);
        MemoryStream ms = new MemoryStream();
        tr.Save(ms, DataFormats.Rtf); // does not contain a definition
        string rtfText = ASCIIEncoding.Default.GetString(ms.ToArray());
        MemoryStream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(rtfText));
           this.richTextBox2.Selection.Load(stream, DataFormats.Rtf);

But I really hate the richtextbox is there no other controls that can hold rich text formatting? Or is there a way in which you can tell a certain control to display rtf?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:57:13+00:00Added an answer on June 2, 2026 at 4:57 am

    You can’t use a TextBlock to display RTF text. But if it’s ok to show the text in a FlowDocumentScrollViewer, you could copy it this way:

    public MainWindow()
    {
        InitializeComponent();
    
        richTextBox.Document = new FlowDocument();
        flowDocumentScrollViewer.Document = new FlowDocument();
    }
    
    private void CopyDocument(FlowDocument source, FlowDocument target)
    {
        TextRange sourceRange = new TextRange(source.ContentStart, source.ContentEnd);
        MemoryStream stream = new MemoryStream();
        XamlWriter.Save(sourceRange, stream);
        sourceRange.Save(stream, DataFormats.XamlPackage);
        TextRange targetRange = new TextRange(target.ContentStart, target.ContentEnd);
        targetRange.Load(stream, DataFormats.XamlPackage);
    }
    
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        CopyDocument(richTextBox.Document, flowDocumentScrollViewer.Document);
    }
    

    Get an overview of Flow Documents here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm try to set the Foreground colour on a Hyperlink using a Style object
I have MyCollection of MyPOCO object (that has two string properties). When I try
I am try to Make a Image Button User control. But When I set
I'm try to display three different values within a listbox using hub tile and
I have a very simple StopWatch application in Silverlight. I have the following private
I just try to understand the concept of the ItemsPanelTemplate. For this i built
I have a problem with a databinding in WPF. When I try to use
I've scoured the Internet but my search-foo must not work if it's out there
I have a stack panel and I have set its datacontext to my custom
I am using a Dispatch timer set to fire every 20 seconds in which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.