Acccess underlying text from RadSyntaxEditor

3 posts, 1 answers
  1. Tim
    Tim avatar
    3 posts
    Member since:
    Jun 2019

    Posted 01 Jan Link to this post

    Hi,

    I'm working with the RadSyntaxEditor (WPF R3 2019) and loving it. It is a great control with lots of potential for our team.

     

    The issue I have is simple and I feel silly having to ask something so trivial, but is there a way access the underlying text of the TextDocument? We need it to write to a stream and save the document after editing. I've tried looking in the TextDocument and TextSnapShot objects, iterating all the lines and spans, and calling all their ToString() methods, but nothing seemed to work. Is there a way to access the raw text from the rope, or even the rope itself?

     

    Thank you ahead of time for your help,

    Happy New Year.

    Tim

  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    3123 posts

    Posted 03 Jan Link to this post

    Hello Tim,

    Thank you for your kind words first. To access all text from the current document you can use:

                string alltext = this.syntaxEditor.Document.CurrentSnapshot.GetText();
    

    Also you can get a particular line then get its text with:

                string lineText = this.syntaxEditor.Document.CurrentSnapshot.GetLineFromPosition(this.syntaxEditor.CaretPosition.Index).GetText();
    
    or
    
     string line25Text = this.syntaxEditor.Document.CurrentSnapshot.GetLineFromLineNumber(25).GetText();

    Ropes are internal structures for now. However, if certain demand requires them to be more visible we will take it into consideration. We will be glad to receive any feedback regarding the usage of this component. 

    Regards,
    Petar Mladenov
    Progress Telerik

    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Tim
    Tim avatar
    3 posts
    Member since:
    Jun 2019

    Posted 03 Jan in reply to Petar Mladenov Link to this post

    Awesome. Thank you so much. I eventually figured this out after messing around with some of the document events. I don't know why, but I expected it to be a property for some reason.

     

     

     

Back to Top