Getting theme colors in a Visual Studio Classifier extension

I am creating a syntax highlighting extension for the Property Language in Visual Studio and have already built the / tagger classifier. However, I am stuck in setting / choosing the right colors for different tags (i.e. Keys, values, comments).

I want the colors to match the current Visual Studio theme. Now they are hardcoded (see ForegroundColor = ...):

[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = "PropertiesKeyTypeDefinition")]
[Name("PropertiesKeyFormat")]
[Order(Before = Priority.Default)]
internal sealed class PropertiesKey : ClassificationFormatDefinition {
    public PropertiesKey() {
        DisplayName = "Properties Key";
        ForegroundColor = Color.FromRgb(86, 156, 214);
    }
}

What I have found so far:

, , ',' String '' ', VS Tools -> Options -> Environment -> Fonts and Colors, , .

+4
1

EnvironmentColors ThemeResourceKey.

SolidColorBrush :

private static SolidColorBrush ToBrush(ThemeResourceKey key)
{
    var color = VSColorTheme.GetThemedColor(key);
    return new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));
}

:

[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = "PropertiesKeyTypeDefinition")]
[Name("PropertiesKeyFormat")]
[Order(Before = Priority.Default)]
internal sealed class PropertiesKey : ClassificationFormatDefinition {
    public PropertiesKey() {
        DisplayName = "Properties Key";
        ForegroundColor = ToBrush(EnvironmentColors.ClassDesignerCommentTextColorKey);
    }
 }

:

ThemeResouceKey

VSColorTheme.GetThemedColor

:

ThemeResourceKey

VS

0

Source: https://habr.com/ru/post/1651875/


All Articles