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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:15:05+00:00 2026-06-16T04:15:05+00:00

I am trying to create a custom Undo/Redo manager for my RichTextBox Control. I

  • 0

I am trying to create a custom Undo/Redo manager for my RichTextBox Control. I insert a char in a Run and save the insertion position and the Run and other information in Undo Stack.

When I try to Undo, I remove the inserted char. After that I set the CaretPosition by this line of code:

CaretPosition = run.ContentStart.GetPositionAtOffset(position);

Everything is fine when I do not start a new Paragraph.

When I press enter and start a new paragraph and I want to undo, something strange happens. Let me explain more:

1- I press return and a new Paragraph is generated.
2- I call Undo.
3- It reaches the above line of code and this exception is thrown: Cannot set CaretPosition to be outside of RichTextBox.

I think this happens because run.Parent==null and not its parent paragraph (This run is on the first paragraph, I mean the paragraph which I pressed return). When I save this run into Undo Stack, Its parent is not null.

I saw the source code of ContentElement.cs (Run’s base class). It is written:

internal DependencyObject _parent;
internal DependencyObject Parent  { get { return _parent; } }

How can this _parent property become null after some changes and how can I prevent this from happening?

Update
(assume I write “123” in the 1st paragraph.)
The first paragraph exists in Document.Blocks and It has a run with “123” in it. But it is a different run. Does this means that a new run is generated?! I’m really confused.

Thanks.

  • 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-16T04:15:06+00:00Added an answer on June 16, 2026 at 4:15 am

    There is big probability that I’m wrong, but try to remove 2 last chars when it is new paragrpah. I think that you are getting this error because when you press return it inserts two characters: \r\n (carret return + new line)

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

Sidebar

Related Questions

I am trying to create custom templated control based on a ListBox to display
I'm trying to create a custom server control (WebControl) with a text box. I
I am trying to create a custom objects manager as described https://docs.djangoproject.com/en/dev/topics/db/managers/#modifying-initial-manager-querysets I am
I am trying to create a custom CStatic control in vc++ and have a
I am trying to create a custom control based on the TCustomComboBox in Delphi
Im trying to create a custom version of the RequiredAttribute to replace the built
I'm trying to create a custom TabItem that is dynamically added to a TabControl
I am trying to create a custom User library in CodeIgniter. Inside this library
I'm trying to create a custom SELECT query to find my Personal Best races
I'm trying to create a custom form input that utilizes some images, it should

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.