【问题标题】:Getting theme colors in Visual Studio Classifier extension在 Visual Studio 分类器扩展中获取主题颜色
【发布时间】:2016-08-20 11:38:12
【问题描述】:

我正在 Visual Studio 中为 Properties language 构建语法突出显示扩展,并且已经构建了分类器/标记器。 然而,我一直在为不同的标签(即键、值、cmets)设置/选择正确的颜色。

我想让颜色遵循 Visual Studio 的当前主题。现在它们是硬编码的(请参阅ForegroundColor = ...): p>

[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);
    }
}

到目前为止我发现了什么:

如果可能的话,我想使用用于 'Keyword'、'String' 和 'Comment' 的颜色,这些颜色可以在 VS 中的Tools -> Options -> Environment -> Fonts and Colors 中找到,同样,按照当前主题。

【问题讨论】:

    标签: c# visual-studio plugins syntax-highlighting vsix


    【解决方案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 Colors

    【讨论】:

      猜你喜欢
      • 2015-10-01
      • 1970-01-01
      • 2013-09-25
      • 2018-04-17
      • 2017-07-30
      • 2013-05-17
      • 1970-01-01
      • 2017-07-01
      • 2012-08-20
      相关资源
      最近更新 更多