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 8785419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:21:20+00:00 2026-06-13T21:21:20+00:00

I’m creating a chat app in Windows 8 Windows Metro Style App. I need

  • 0

I’m creating a chat app in Windows 8 Windows Metro Style App. I need to append the conversation in a richtextblock or textblock in XAML. Would somebody tell me the equivalent for this Code block?

public void AppendConversation(string str)
{
    conversation.Append(str);
    rtbConversation.Text = conversation.ToString();
    rtbConversation.Focus();
    rtbConversation.SelectionStart = rtbConversation.Text.Length - 1;
    rtbConversation.ScrollToCaret();
    rtbSendMessage.Focus();
}
  • 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-13T21:21:21+00:00Added an answer on June 13, 2026 at 9:21 pm

    Since WPF uses System.Windows.Controls instead of System.Windows.Forms, we must consider the following

    1. System.Windows.Controls.RichTextBox does not have a property for Text to set its value, we may set its value creating a new class of TextRange since the control depends on TextPointer which can be defined using TextRange

    string _Text = ""
    new TextRange(
      rtbConversation.Document.ContentStart,
      rtbConversation.Document.ContentEnd).Text = _Text;
    

    2. Selections in System.Windows.Controls.RichTextBox does not depend on int yet they are held by TextPointer. So, we can’t say

    rtbConversation.SelectionStart = rtbConversation.Text.Length - 1;
    

    but we can say

    int TextLength = new TextRange(
      rtbConversation.Document.ContentStart,
      rtbConversation.Document.ContentEnd).Text.Length;
    TextPointer tr = rtbConversation.Document.ContentStart.GetPositionAtOffset(
      TextLength - 1, LogicalDirection.Forward);
    rtbConversation.Selection.Select(tr, tr);
    

    which will do the same as rtbConversation.SelectionStart = rtbConversation.Text.Length - 1;

    Remark: You can always retrieve the beginning of the selection in WPF using RichTextBox.Selection.Start

    Notice: RichTextBox.Selection.Start outputs a class of name TextPointer but not a struct of name int


    3. Finally, System.Windows.Controls.RichTextBox does not have a definition for ScrollToCaret();. In this case, we may use one of the following voids regarding your control rtbConversation

    rtbConversation.ScrollToEnd();
    rtbConversation.ScrollToHome();
    rtbConversation.ScrollToHorizontalOffset(double offset);
    rtbConversation.ScrollToVerticalOffset(double offset);
    

    So, your void should look like this in WPF

    Example

    public void AppendConversation(string str)
    {   
        conversation.Append(str) // Sorry, I was unable to detect the type of 'conversation'
        new TextRange(rtbConversation.Document.ContentStart,
                      rtbConversation.Document.ContentEnd).Text =
                        conversation.ToString();
        rtbConversation.Focus();
        int TextLength = new TextRange(rtbConversation.Document.ContentStart,
                                       rtbConversation.Document.ContentEnd).Text.Length;
        TextPointer tr = rtbConversation.Document.ContentStart.GetPositionAtOffset(
            TextLength - 1, LogicalDirection.Forward);
        rtbConversation.Selection.Select(tr, tr);
        rtbConversation.ScrollToEnd();
        rtbSendMessage.Focus();
    }
    

    Thanks,

    I hope you find this helpful 🙂

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

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.