SyntaxEditor highlighting background of substrings

Editors for WPF Forum

Posted 3 months ago by Daniel Constantin - ModuleWorks GmbH
Version: 19.1.0687
Avatar

Hi,

I want to use the Syntax Editor component with some custom language created by me.

I need to be able to highlight/change the background for selected words and also substrings.

How can I do this ?

Kind regards,

Daniel

Comments (3)

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Daniel,

Can you provide some more detailed information on your request?  Please make some mockup screenshots that show what you are trying to achieve and that would probably be most helpful.  You can link to them in a reply here, or if you would prefer, start a support ticket and you can attach the screenshots there.  If you do create a separate support ticket, reference this thread in your e-mail.  Thanks!


Actipro Software Support

Posted 3 months ago by Daniel Constantin - ModuleWorks GmbH
Avatar

Hi,

I did something similar for a normal TextBlock using Inlines and Runs.

  txtBlock.Inlines.AddRange(new Inline[] {
                    new Run(text.Substring(0, index)),
                    new Run(text.Substring(index, highlightText.Length))
                        {
                            Background = highlightColor,
                            Foreground = foregroundColor
                        }
                });

For example in this code snippet I can change the foreground color and also the background color for that substring. I saw that I need to create my own language for the syntax editor and I think I am able to change the foreground text for some specific words but I was wondering if I can change the background also.

Kind regads,

Daniel

The latest build of this product (v21.1.1) was released 3 months ago, which was before the next post in this thread.
Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Daniel,

Yes, the SyntaxEditor highlighting styles support changing foreground, background, bold, italic, underline, etc.  In general if you are doing syntax highlighting, you want to make a lexer that will tokenize the code being edited in the SyntaxEditor.  Each token gets assigned a classification type that identifies the kind of thing represented by the token (e.g. keyword, comment).  And each classification type can have a highlighting style registered for it, so that syntax highlighting is applied for tokens using that classification type.  Background alterations can be part of that highlighting style.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.