locked
RichEditBox: On mouse click in new line richeditbox loses the text formatting RRS feed

  • Question

  • I am using RichEditBox in my app.I have a color palette using which the user can set the foreground color of text in richeditbox(something like MS word).
    Issue : I start typing with foreground color set to green or red or any color other than black and hit the enter key to move to new line.Before starting to type in the new line I navigate back to the previous line (let’s say to make some correction) using keyboard Up key. Now I again place the cursor in the new line using mouse left click and start typing, the foreground color of text is reset to black and not the color that I have chosen from the palette.
    However this issue does not come if I use only keyboard to navigate between new line and previous lines.
    XAML text editing sample(C# - http://code.msdn.microsoft.com/windowsapps/XAML-text-editing-sample-fb0493ad)for windows 8.1 can be used to reproduce the issue. 
    Steps to reproduce the issue:
    1. Open Scenario 6 in sample.
    2. Open the color palette and choose a color(e.g.- Green)
    3. Type something in the richeditbox and hit enter to move to next line.
    4. Before starting to type move the cursor back to the previous line using keyboard Up key.
    5. Use mouse left click to bring the cursor back to new line.Start typing and you'll notice that the foreground color has been reset to black.
    Is this a bug or do I need to handle some event in my code to avoid this issue?


    Wednesday, January 8, 2014 8:34 AM

All replies

  • You didn't include a code snippet demonstrating how you are setting the color and I'm not on a system I can easily look up the sample right now, but I suspect you're setting the color just on the current selection. New characters entered at the end of the selection will inherit that format, but when you click to move to the cursor you end up with the control's default character format.

    Wednesday, January 8, 2014 8:47 AM
    Moderator
  • Hi, 
    Thanks for reply,I am using the following code to set the color.

    ITextCharacterFormat charFormatting = editor.Document.Selection.CharacterFormat;
    charFormatting.ForegroundColor = Colors.Red;
    Yes, I am setting the color for only the current selection and if I hit enter and move to new line and start typing the new text retains the selected foreground color(Red in this case). It is only when I move to the new line using mouse click this issue occurs.

    Wednesday, January 8, 2014 9:07 AM
  • Yup. You're doing what I described in my previous post. New characters get the same format as the one at the cursor, so when you keep typing you get the same format. When you mouse to the new line you get the default format for the document since you aren't continuing on from the selection you changed. If you want to change the default color then change the default character format instead (or in addition to) the selection's format.
    Wednesday, January 8, 2014 11:56 AM
    Moderator
  • Yup, got your point.

    However I tried the following two code snippets but still when I navigate to new line using mouse click all the formatting is reset.

    1.

    ITextCharacterFormat charFormatting = editor.Document.Selection.CharacterFormat;
    charFormatting.ForegroundColor = Colors.Red;
    editor.Document.SetDefaultCharacterFormat(charFormatting);
    2.
    ITextCharacterFormat charFormat = editor.Document.GetDefaultCharacterFormat();
    charFormat.ForegroundColor = Colors.Red;
    editor.Document.SetDefaultCharacterFormat(charFormat);
    Wednesday, January 8, 2014 2:44 PM