I'm building a syntax highlighting extension for the Properties language in Visual Studio and already built the classifier/tagger. I'm stuck however at setting/choosing the right colors for the different tags (i.e. keys, values, comments).
I'd like to make the colors follow the current theme of Visual Studio. Right now they're hard-coded (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've found so far:
If possible, I'd like to use the colors used for 'Keyword', 'String' and 'Comment' colors which can be found in VS in Tools -> Options -> Environment -> Fonts and Colors
, again, in accordance with the current theme.
Here's how to change the color theme of the IDE frame and the tool windows in Visual Studio. On the menu bar, choose Tools > Options. In the options list, choose Environment > General. In the Color theme list, choose either the default Dark theme, the Light theme, the Blue theme, or the Blue (Extra Contrast) theme.
You can customize your active Visual Studio Code color theme with the workbench. colorCustomizations user setting. Note: If you want to use an existing color theme, see Color Themes where you'll learn how to set the active color theme through the Preferences: Color Theme dropdown (Ctrl+K Ctrl+T).
Based on the EnvironmentColors you can get a ThemeResourceKey.
That key can than be transformed into a SolidColorBrush using this function:
private static SolidColorBrush ToBrush(ThemeResourceKey key)
{
var color = VSColorTheme.GetThemedColor(key);
return new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));
}
So assigning it to your foreground becomes:
[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);
}
}
Documentation:
ThemeResouceKey
VSColorTheme.GetThemedColor
Extra:
This might be helpful in selecting the right ThemeResourceKey
VS Colors
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With