Method of moving big amount of text

Haviv Elbsz 2,071 Reputation points
2023-12-03T09:54:57.1933333+00:00

Hello all. I use maui net 8 17.9 preview android ver 14. Is there a method of moving a big amount of text to the editor control without choking the editor control. currently I use this statement editor.text = bigtext: this freeze the app. I have an idea to move the text in chunks manner when the user scrolls the editor text the app will move a chunk of text but I don't know how to do that. can someone help. Thank you.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,207 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 38,911 Reputation points Microsoft Vendor
    2023-12-04T03:05:10.0033333+00:00

    Hello,

    I have an idea to move the text in chunks manner when the user scrolls the editor text the app will move a chunk of text but I don't know how to do that.

    The Editor doesn't have scroll events, so it is not possible to implement this feature in this way.

    You could use a button to remind the user if more text can be loaded.

    In the example below, the application uses a pager, which loads in 500-character increments, and if there is still loadable data, the button will display "See More".

    <Editor x:Name="edi"/>
    <Button x:Name="more_button"/>
    
    int cut_lenth = 500; //The size of the pagination
    int index = 0;
    //pagination
    private ArrayList GetSeparateSubString(string txtString, int charNumber)
    {
        ArrayList arrlist = new ArrayList();
        string tempStr = txtString;
        for (int i = 0; i < tempStr.Length; i += charNumber)
        {
            if ((tempStr.Length - i) > charNumber)
            {
                arrlist.Add(tempStr.Substring(i, charNumber));
            }
            else
            {
                arrlist.Add(tempStr.Substring(i));
            }
        }
        return arrlist;
    
    }
    public MainPage()
    {
        InitializeComponent();
        string str = "";
        for (int i = 0; i < 700; i++)
        {
            str += i.ToString();
        }
        var pages = GetSeparateSubString(str, cut_lenth);
        if (pages.Count > index)
        {
            edi.Text = pages[index].ToString();
            index++;
            more_button.Text = "See More";
            more_button.Clicked += (s, e) =>
            {
                if (pages.Count > index)
                {
                    edi.Text += pages[index].ToString();
                    index++;
                    if (pages.Count <= index)
                    {
                        more_button.Text = "Finished";
                    }
                }
            };
        }
        else
        {
            more_button.Text = "Finished";
        }
    }
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful