SyntaxEditor + Web Lang. Addon, highlighting reserved words issue

SyntaxEditor for WPF Forum

Posted 6 years ago by Daniil Monin - Software Architect, Sovacode Software
Version: 13.2.0591
Avatar

Hello!

I have issue with SyntaxEditor and Web Languages addon.

I have a code:

<editor:SyntaxEditor x:Name="CodeEditor" IsLineNumberMarginVisible="True" IsOutliningMarginVisible="True" IsCurrentLineHighlightingEnabled="True" Text="{Binding Text, Mode=TwoWay, NotifyOnSourceUpdated=True}">
syntaxeditor:EditorDocument xml:space="preserve">
                
                <syntaxeditor:EditorDocument.Language>
                    <syntaxeditor:JavaScriptSyntaxLanguage />
                </syntaxeditor:EditorDocument.Language>
                
            </syntaxeditor:EditorDocument>
        </editor:SyntaxEditor>

 As you can see Text is binded to my view model property Text:

        /// <summary>
        /// Gets or sets the text.
        /// </summary>
        /// <value>The text.</value>
        public virtual string Text
        {
            get { return _text; }
            set
            {
                _text = value;

                OnPropertyChanged(() => Text);
            }
        }

But when my application use a Dark Theme (Metro Dark Theme) all resrved words like "function, void etc." from JavaScriptSyntaxLanguage highliting with color to hard read, because it's very bright like ~RGB 0:0:255. But in demo app I see nice color when theme is dark, and I suppose it's turquoise color.

Could you help me with that?

I don't know how to attach an image here, but I believe you will understand my poor english :)

Comments (2)

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

Hi Danill,

That's right because languages only define colors for one theme (which defaults to light).  However you can update the ambient highlighting style registry to have different styles registered for its known classification types.  You'd want to run through each of those and entries and update the highlighting styles as appropriate.

Our Sample Browser has this in its WindowsApp.xaml.cs file:

// Update the SyntaxEditor highlighting style registry if the theme changes backgrounds from light to dark, or vice versa
ThemeManager.CurrentThemeChanged += (sender, args) => {
	ActiproSoftware.ProductSamples.SyntaxEditorSamples.Common.SyntaxEditorHelper.UpdateHighlightingStyleRegistryForThemeChange();
};

That calls the helper method when the theme changes.  The helper method checks to see if we have switched from a dark to light theme or vice-versa.  In either of those scenarios, it will effectively unregister all classification types from the AmbientHighlightingStyleRegistry, then re-register some of the common types.  At this point you are set up again for light theme.  Note that at this point you want to make sure you have any classification types registered that might be changed for a dark theme.  If we are going to a light theme, we quit.  If we are going to a dark theme, we load our Dark.vssettings file, which will override the styles for the matching classification types that are found in the registry.

This procedure is a tad complex and could definitely be improved in some scenarios.  But the main point is that in response to theme changes, you want to update the styles as appropriate for the classification types you need to use in your lexers.  There are many ways to accomplish that, one is above.

You also could choose to just maintain a separate "dark" highlighting style registry (with appropriate dark styles) and assign that to SyntaxEditor.HighlightingStyleRegistry when the dark theme is active.  Then remove it after.


Actipro Software Support

Posted 6 years ago by Daniil Monin - Software Architect, Sovacode Software
Avatar

Hi!

Thank you for quick response! I suppose it will resolve my issue. Thanks!

The latest build of this product (v2019.1 build 0683) 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.