【发布时间】:2020-05-05 21:04:16
【问题描述】:
我正在评估 Telerik 的 RadRichTextBox 控件。我的主要目标是添加自定义格式的代码块。
因此,我创建了自己的样式并注册了它们。 (见下面的代码)
问题:虽然我可以设置关键字和 cmets 的样式,但我不知道如何为“普通代码”设置字体样式。
如下所示,我为每个可能的“分类类型”设置了一个样式,但“普通代码”没有设置样式。
结果是,关键字和 cmets 具有所需的字体大小和颜色,但“普通代码”没有样式。
我的问题:如何在“普通代码”的代码块中设置字体样式?
StyleDefinition styleKeyWord = new StyleDefinition(cl.GetCodeLanguage.Name + "StyleKeyword", StyleType.Character);
styleKeyWord.SpanProperties.ForeColor = DarkTheme.LanguageColorKeyword;
styleKeyWord.SpanProperties.FontFamily = DarkTheme.LanguageFontFamily;
styleKeyWord.SpanProperties.FontSize = Unit.PointToDip(DarkTheme.LanguageFontSize);
StyleDefinition styleString = new StyleDefinition(cl.GetCodeLanguage.Name + "StyleString", StyleType.Character);
styleString.SpanProperties.ForeColor = DarkTheme.LanguageColorString;
styleString.SpanProperties.FontFamily = DarkTheme.LanguageFontFamily;
styleString.SpanProperties.FontSize = Unit.PointToDip(DarkTheme.LanguageFontSize);
StyleDefinition styleComment = new StyleDefinition(cl.GetCodeLanguage.Name + "StyleComment", StyleType.Character);
styleComment.SpanProperties.ForeColor = DarkTheme.LanguageColorComment;
styleComment.SpanProperties.FontFamily = DarkTheme.LanguageFontFamily;
styleComment.SpanProperties.FontSize = Unit.PointToDip(DarkTheme.LanguageFontSize);
StyleDefinition styleMethod = new StyleDefinition(cl.GetCodeLanguage.Name + "styleMethod", StyleType.Character);
styleMethod.SpanProperties.ForeColor = DarkTheme.LanguageColorString;
styleMethod.SpanProperties.FontFamily = DarkTheme.LanguageFontFamily;
styleMethod.SpanProperties.FontSize = Unit.PointToDip(DarkTheme.LanguageFontSize);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.Attributes, codeLanguage, styleComment);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.CharacterLiteral, codeLanguage, styleComment);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.Comment, codeLanguage, styleComment); //Ok
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.Constants, codeLanguage, styleComment);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.Data, codeLanguage, styleComment);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.ExcludedCode, codeLanguage, styleComment);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.Identifier, codeLanguage, styleComment);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.Keyword, codeLanguage, styleKeyWord); //Ok
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.Literal, codeLanguage, styleComment);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.Method, codeLanguage, styleMethod);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.NumberLiteral, codeLanguage, styleComment);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.Operator, codeLanguage, styleComment);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.PreprocessorKeyword, codeLanguage, styleComment);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.StringLiteral, codeLanguage, styleString);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.Variable, codeLanguage, styleComment);
document.CodeFormatter.RegisterClassificationType(ClassificationTypes.WhiteSpace, codeLanguage, styleComment);
【问题讨论】: