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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:06:26+00:00 2026-05-13T22:06:26+00:00

When I first run my program and type some text in the richtextbox, if

  • 0

When I first run my program and type some text in the richtextbox, if I press enter, which causes the carat to move to a new line, and then press backspace instead of going to the previous line it just moves back a space even though I haven’t typed any text on this new line. I can’t figure out what is happening. What am I doing wrong? And how can I fix it?

Edit:

It looks like the richtextbox is adding a space in front of the first character when I start typing and a space is added in front of every new line I make. I cannot place the carat in front of the space, by clicking in front of it, but I can delete it by using backspace and then everything goes back to normal.

Edit 2: This is the code that seems to be causing the problem, but I can’t figure out why it is doing that:

<RichTextBox.Resources>
     <Style TargetType="{x:Type Paragraph}">
            <Setter Property="Margin" Value="5"/>
     </Style>
</RichTextBox.Resources>
  • 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-05-13T22:06:26+00:00Added an answer on May 13, 2026 at 10:06 pm

    That’s not how the RichTextBox behaves if I just put this into Kaxaml:

    <Page
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Grid>  
        <RichTextBox/>
      </Grid>
    </Page>
    

    This leads me to suspect that there’s something else going on with your code. What is it?

    Edit:

    Well, okay, it’s clear why you’re getting the “space” in front of the caret: you’re applying a style to paragraphs that sets a margin. What’s not clear at all is why pressing BACKSPACE makes it go away.

    How to troubleshoot a problem like this: Add an event handler to your RichTextBox (I used KeyUp), and use XamlWriter to dump its Document property to Console.Out. You’ll see that when it’s first populated, the Document contains:

    <FlowDocument PagePadding="5,0,5,0" AllowDrop="True" NumberSubstitution.CultureSource="User" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
      <Paragraph />
    </FlowDocument>
    

    After you hit BACKSPACE, it looks like this:

    <FlowDocument PagePadding="5,0,5,0" AllowDrop="True" NumberSubstitution.CultureSource="User" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
      <Paragraph Margin="0,5,5,5" />
    </FlowDocument>
    

    It’s a lot more apparent what’s going on if you set the margin in your style to 50 instead of 5. The “space” that you’re seeing in front of the paragraph is in fact the paragraph’s left margin, set by the style in the RTB’s resource dictionary. Since the paragraph has no local Margin property, it’s inheriting the margin from the style.

    When you press BACKSPACE, the left margin gets set to 0. This gives the paragraph’s Margin property a local value, so it stops inheriting from the style.

    If you hit ENTER and add a new paragraph, the new paragraph copies the margins of the previous paragraph. So, essentially, your style stops working.

    This seems like it’s a bug in how the RTB implements EditingCommands.Backspace. What that command’s supposed to do, officially:

    When invoked on an empty selection, this command deletes the character or paragraph separator just before the caret. When invoked on a non-empty selection, this command deletes the selection.

    This command retains any formatting from the deleted selection for content immediately inserted at the same location after this command is invoked.

    I think it’s pretty clear that’s not what it’s actually doing. In fact, if you set the margin to 50, it becomes clear that when the caret’s at the beginning of a paragraph with a margin, and you press BACKSPACE, it reduces that paragraph’s left margin by 20. I can’t see any documented justification for that behavior.

    So, what can you do about this? It sort of depends on why you’re setting that margin in the first place. From your original description, it sounds like you think it’s the margin, and not the fact that BACKSPACE makes it go away, that’s the bug. Well, that’s easy enough to fix; get rid of that style.

    But if you need that margin for some reason, I don’t know what to tell you.

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

Sidebar

Ask A Question

Stats

  • Questions 372k
  • Answers 372k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Unfortunately it's not very easy. You could create your own… May 14, 2026 at 7:15 pm
  • Editorial Team
    Editorial Team added an answer I actually think I see your problem. The insertAtCaret function… May 14, 2026 at 7:15 pm
  • Editorial Team
    Editorial Team added an answer There are ways to keep an app from going to… May 14, 2026 at 7:15 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.