Rendering SyntaxEditor.ActiveView without highlighting

SyntaxEditor for WPF Forum

Posted 4 years ago by Andrew Levine
Version: 19.1.0684
Avatar

Hello, I'm trying to get a screenshot of the SyntaxEditor's text without highlighting styles, but with lexing color coding still intact. What is the best way to prepare the control? Here is my best guess for an editor in single-line mode, but the screenshot keeps coming out with the highlights still inside:

    Public ReadOnly Property Preview As RenderTargetBitmap
        Get
            Dim r As HighlightingStyleRegistry = editor.HighlightingStyleRegistry
            editor.HighlightingStyleRegistry = Nothing
            editor.InvalidateVisual()
            Dim v As EditorView = editor.ActiveView
            Dim bmp As New RenderTargetBitmap(2000, v.VisualElement.ActualHeight, 96, 96, PixelFormats.Pbgra32)
            v.VisualElement.Measure(New Size(2000, v.VisualElement.ActualHeight))
            v.VisualElement.Arrange(New Rect(0, 0, 2000, v.VisualElement.ActualHeight))
            bmp.Render(v.VisualElement)
            editor.HighlightingStyleRegistry = r
            Return bmp
        End Get
    End Property

Comments (2)

Answer - Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

If the editor.HighlightingStyleRegistry is null (the default), then it will use the AmbientHighlightingStyleRegistry.Instance as the registry.  You might want to have the AmbientHighlightingStyleRegistry.Instance registry be the one with all your normal styles and then when you want a limited set, make a new HighlightingStyleRegistry, register only the lexing classification types and highlighting styles you need on it, and them temporarily set that to the editor.HighlightingStyleRegistry property while you take your screenshot.


Actipro Software Support

Posted 4 years ago by Andrew Levine
Avatar

Great idea, thanks!

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

Add Comment

Please log in to a validated account to post comments.