简体   繁体   中英

UWP: Text not visible in RichEditBox control in C# (VS 2017)

I use the RichEditBox control in C# in my program to display a text file with more than 7200 lines. All lines of text may be loaded into the RichEditBox (I checked by debug), but only 7056 lines of text can be displayed. That is. any text from line 7057 onwards is not visible, but accessible. When I tried to decrease some lines' length, it stops displaying at the same line.

I notice that it seems to be a problem for many years. I am wondering if there is a way sorted or there is a workaround. It is appreciated again if someone could help me.

The following is simple test code. I use looping to create a bunch of lines of text which will be loaded to the RichEditText control. We can read the text in the RichEditText box by scrolling. Depending on the memory space allocated, the last line visible in the box is not necessarily the text line in the RichEditText.

C#

public sealed partial class MainPage : Page {

    public MainPage()
    {
            this.InitializeComponent();

            string fileText = "";
            string str = "  This is test text to test RichEditText control functions";
            for (int i = 1; i <= 20000; i++)
            {
                fileText = fileText + "Line" + i.ToString("D6") + str; 
                if (i < 20000)
                    fileText += "\r\n";
            }

            DocPage.IsReadOnly = false;
            DocPage.TextDocument.SetText(TextSetOptions.None, fileText);
            DocPage.IsReadOnly = true;
            RichEditTextRange range; // text range, in paragraph.
            range = (RichEditTextRange)DocPage.TextDocument.GetRange(0, 1);
            range.SetIndex(TextRangeUnit.Paragraph, -1, true);
            // Get the total lines of the text in the RichEditText
            int count2 = range.GetIndex(TextRangeUnit.Paragraph);
            // Get the text of the last line in the RichEditText
            range.GetText(TextGetOptions.UseCrlf, out string last);
    }

}

This is a known issue for TextBox and RichEditBox both in UWP and WinUI. Currently, there is no good workaround for this except loading less text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM