Line count in WPF

SyntaxEditor for WPF Forum

Posted 14 years ago by James Deadman
Version: 9.2.0514
Avatar
Hello,

We have moved from the WinForms SyntaxEditor to the WPF edition. I need to get the total line count for a Document which in WinForms was 'editor.Document.Lines.Count'.

How do i get the line count of a document in WPF please?

Thanks.

Comments (3)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi James,

The WPF version introduces thread-safe ITextSnapshot's which are versioned read-only instances of a document at any time. So you use those now when reading a document. That way you know that any text changes that occur while you are reading it, are not updating the snapshot you are looking at. The text changes create a new snapshot that you can get later. The most current snapshot is always available from the document's CurrentSnapshot property.

So the updated code would be "editor.Document.CurrentSnapshot.Lines.Count".


Actipro Software Support

Posted 14 years ago by James Deadman
Avatar
Hello,

Thanks for your reply.

May i also ask the difference between the CurrentSnapshot of the Document and of the ActiveView (IEditorView), how do these differ please?

For example, i have a GoTo dialog that i need to show the maximum line for.

Thanks,
James
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
They will typically be the same. The only time they may be off is if the document is just being updated and is about to raise text changed events, but the view hasn't yet received the event to know to update to a new snapshot. So the view snapshot is the one that all the view line layouts are currently based on.


Actipro Software Support

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.