c# – 在Visual Studio分类器扩展中获取主题颜色
我正在为Visual Studio中的
Properties language构建语法高亮扩展,并且已经构建了分类器/标记器.
然而,我坚持为不同的标签设置/选择正确的颜色(即键,值,注释). 我想让颜色遵循Visual Studio的当前主题.现在它们是硬编码的(参见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); } } 到目前为止我发现了什么: > This question假设我的问题已经回答了. 如果可能的话,我想使用用于“Keyword”,“String”和“Comment”颜色的颜色,这些颜色可以在工具中的VS中找到 – >选项 – >环境 – >字体和颜色再次符合当前主题. 解决方法
基于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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |