locked
RichEditBox.SetText with TextSetOptions.FormatRtf ignores formatting RRS feed

  • Question

  • I've encounter the problem when I call RichEditBox.SetText with TextSetOptions.FormatRtf.

    I attached repro project that is modified version of  8.1 app sample.

    In repro project,I create new RichEditBox and get rtf formatted text from another RichEditBox and set it to new one.

    When I set text immediately after creating RichEditBox,it loses all formatting. With some delay,it doesn't.

    To repro,

    1. Select "6) RichEditBox and WinRT TOM" from Select Scenario located in the upper-left part of.

    2.Edit rtf text in the RichEditBox located beneath Bold button.You can copy from Wordpad or apply formatting from buttons like Bold,Italic,12Pt,Font Color.

    3.Press CreateNew or CreateNewDelay.Pressing CreateNew creates RichEditBox then set edited text immediately.Pressing CreateNewDelay creates then set text with some delay. You can change delay by DelayTime textBox which means milli seconds. Sometime delay 1 msec is enough ,sometime you need more.

    This is the repro project

    Regards,


    cyclops

    Wednesday, November 20, 2013 7:48 PM

Answers

  • i could reproduce the problem but only with font sizes. those got lost. i changed your createnew method with this:

    private void CreateNewButtonClick(object sender, RoutedEventArgs e)
            {
                var reb = new RichEditBox()
                {
                    Width = 200,
                    Height = double.NaN,
                };
                string str;
                editor.Document.GetText(TextGetOptions.FormatRtf, out str);
                rebStack.Children.Add(reb);
                reb.Loaded += (x, xx) =>
                {
                    reb.Document.SetText(TextSetOptions.FormatRtf, str);
                };
            }

    as you can see i waited till the new control was loaded and then set the text. it solved the problem for me.


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Wednesday, November 20, 2013 10:32 PM

All replies

  • i could reproduce the problem but only with font sizes. those got lost. i changed your createnew method with this:

    private void CreateNewButtonClick(object sender, RoutedEventArgs e)
            {
                var reb = new RichEditBox()
                {
                    Width = 200,
                    Height = double.NaN,
                };
                string str;
                editor.Document.GetText(TextGetOptions.FormatRtf, out str);
                rebStack.Children.Add(reb);
                reb.Loaded += (x, xx) =>
                {
                    reb.Document.SetText(TextSetOptions.FormatRtf, str);
                };
            }

    as you can see i waited till the new control was loaded and then set the text. it solved the problem for me.


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Wednesday, November 20, 2013 10:32 PM
  • It works fine!! Thanks.

    I don't know why it works,but I should do something after Control loaded.


    cyclops

    Saturday, November 23, 2013 4:30 AM