The Font Color of the string is the same even if the theme is changed.

SyntaxEditor Python Language Add-on for WPF Forum

Posted 3 months ago by Kim Jiho - Ansys
Version: 22.1.2
Platform: .NET 4.8
Environment: Windows 10 (64-bit)
Avatar

Screenshot

public static class ActiproService
{
    private static bool isDarkThemeActive;

    public static bool GetIsDarkThemeActive() => ThemeManager.IsDarkTheme(ThemeManager.CurrentTheme);

    public static void Initialize()
    {
        ThemeManager.CurrentThemeChanged += (sender, args) =>
        {
            UpdateHighlightingStyleRegistryForThemeChange();
        };

        ThemeManager.AreNativeThemesEnabled = true;

        AmbientParseRequestDispatcherProvider.Dispatcher = new ThreadedParseRequestDispatcher();

        var cachePath = Path.GetFullPath("Package Repository");
        AmbientPackageRepositoryProvider.Repository = new FileBasedPackageRepository(cachePath);
    }

    public static void SetTheme(string themeName)
    {
        ThemeManager.BeginUpdate();

        try
        {
            ThemeManager.UnregisterAutomaticThemes();
            ThemeManager.CurrentTheme = themeName;
        }
        finally
        {
            ThemeManager.EndUpdate();
        }
    }

    public static void UpdateHighlightingStyleRegistryForThemeChange()
    {
        var oldIsDarkThemeActive = isDarkThemeActive;

        isDarkThemeActive = GetIsDarkThemeActive();

        if (isDarkThemeActive != oldIsDarkThemeActive)
        {
            var classificationTypes = AmbientHighlightingStyleRegistry.Instance.ClassificationTypes.ToArray();

            foreach (var classificationType in classificationTypes)
            {
                AmbientHighlightingStyleRegistry.Instance.Unregister(classificationType);
            }

            new DisplayItemClassificationTypeProvider().RegisterAll();
            new PythonClassificationTypeProvider().RegisterAll();
        }
    }
}
protected override void OnStartup(StartupEventArgs e)
{
    ActiproService.Initialize();
    ActiproService.SetTheme(ThemeNames.Dark);

    base.OnStartup(e);
}

I am using SyntaxEditor as a PropertyEditor in PropertyGrid.

When using Dark Theme, the ForeColor of the string in double quotation marks is the same as Light Theme, so it is hard to see. (Please check the screenshot)

The attached code is the code that I set Actipro, and there is no code that sets Theme or any color in other codes.

I need a way to solve this problem or a way to display all the strings in white (or black).

 

Comments (2)

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

Hello,

Looking at your UpdateHighlightingStyleRegistryForThemeChange logic, you have everything in there from our sample that will effectively reset all highlighting styles for display and Python to their light defaults.  What you are missing is the last part of our sample UpdateHighlightingStyleRegistryForThemeChange method where if it's now a dark theme, it will load a file that overrides the highlighting styles.  Since that logic isn't in your code, the light styles (other than the plain text color, which probably is coming down from the control's Foreground) remain in your case.

If you didn't wish to load a Dark.vssettings file like in our sample, you could alternatively change highlighting style foreground colors programmatically at the end of UpdateHighlightingStyleRegistryForThemeChange.

On a side note, we want to improve how themes works in SyntaxEditor to make it easier to define light and dark themes and switch between them.  I will add this thread to that TODO item's notes.


Actipro Software Support

Posted 3 months ago by Kim Jiho - Ansys
Avatar

Thank you for your advise.

I didn't think the highlighting would change if ".vsettings" was imported.
I hope the next version will be added with built-in features.

The latest build of this product (v22.1.4) was released 25 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.