The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
[UWP]C# UWP Trying to construct data in code behind and add it to RichEditBox RRS feed

  • Question

  • I am going to put up a window and display the Ssystem Information.  Got the data, now I need to format the text and put it to a RichEditbox

    My old  code use a RichTextBox, but as I understand it, the REB is the better one to use, RichTxtBox isnt available. So I added text to a Run.  Then adding the Run to Paragraph. No errors with that. I can't seem to find out how to add the paragraph to the REB. Since the Paragraph and Run are there, it would seem that there is a way to add it.

    I did find this in the docs

     myREB.Document.SetText(Windows.UI.Text.TextSetOptions.None, "This is some sample text"); 

       same results with TextsetOptions.formatRtf

    Running un that statement crashes  with

        System.UnauthorizedAccessException: 'Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))'

    SO.. the real question.  Anyone got a link to some doc's that is up to date, runs in code behind,  or is  an example.  Or got some sample code.  Or the one line to add it.

       Paragraph paragraph = new Paragraph();
       Run run = new Run(); 
       run.Text = "Device Family:  " + "Some text" + "\n\n";
       paragraph.Inlines.Add(run);

      REB.Document ????????



    Sunday, September 15, 2019 11:32 PM

Answers

  • Hi,

    I've tried your code that using SetText(), it works correctly in my side. I test it in a blank app targeting build 1903. In general, this shouldn't give exception like UnauthorizedAccessException. Could you please test this in a blank app? If you could reproduce this in the blank app, could you please share me the code snippet that could reproduce it?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ScCrow2 Tuesday, September 17, 2019 4:25 AM
    Monday, September 16, 2019 3:28 AM
    Moderator

All replies

  • Hi,

    I've tried your code that using SetText(), it works correctly in my side. I test it in a blank app targeting build 1903. In general, this shouldn't give exception like UnauthorizedAccessException. Could you please test this in a blank app? If you could reproduce this in the blank app, could you please share me the code snippet that could reproduce it?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ScCrow2 Tuesday, September 17, 2019 4:25 AM
    Monday, September 16, 2019 3:28 AM
    Moderator
  • Hey Roy

    This, I think is the last question I had out there. Till the next one.

    I have no Idea what happened. I kept getting the error. New test app, same results Then I moved that line myReb.Document….) up a few lines. Same,,repeat

    Then I moved it to the top. It worked.  Slowly, I started appending text from the run.text to a string, then slowly moving it down for about 15 writes. I then expected the last line to be causing the problem (paragraph.Inlines.Add(run)), since it was the only one different.  It worked, and continues to work. All the other things I had tried were getting the same result previously too. I did not try them all again.  So I ended up Not using Run and Paragraphs.  I just appended info to a string and wrote it

             myREB.Document.SetText(Windows.UI.Text.TextSetOptions.FormatRtf, sString);

    I have no explanation. It's working and I can use it.

    One minor thing.  My code samples that I found used a command  myREB.Document.Blocks.Add(paragraph)  That command is not available.  It dies after Document. So the run statements get added to paragraphs, which in the end get added to the REB. Since the Run and Paragraph are there, there must be a way of adding them. I cant find it. 

    Should someone want to do more, like fonts and colors, etc., It is after all, a RTF control.  That command may be needed. If you, or someone, finds a link to doco, please post it.  It seems like most of my searches turn up old data that most of the time is wrong.

    Tuesday, September 17, 2019 4:25 AM
  • I found the one problem.  I  set IsReadOnly to true when I noticed that users could change the data although couldn't save it.  That change also prevented me from making changes. So when I tried to add text,  ACCESS error.  SO now,  at the beginning of the proc, allow changes and set it back to off at the end.  Duh!
    Tuesday, September 17, 2019 3:28 PM