I want to persist any changes the user makes to highlighting styles between runs of my application. Is there a 'right' way to load/save the HighlightingStyleRegistry?
InitializeComponent();
_xmlSchemaResolver = new XmlSchemaResolver();
LoadSchema(XmlSchema);
_xmlSyntaxLanguage = new XmlSyntaxLanguage();
_xmlSyntaxLanguage.RegisterXmlSchemaResolver(_xmlSchemaResolver);
syntaxEditor.Document.Language = _xmlSyntaxLanguage;
LoadSavedHighlightingStyles();
bool loadSucceeded = true;
_editorFontSettings = new EditorFontSettings();
_editorFontSettings.Reload();
if (_editorFontSettings.FontStyles != null && _editorFontSettings.FontStyles.Count > 0)
{
_loadedStyleRegistry = new HighlightingStyleRegistry();
_loadedStyleRegistry.Description = "Biml Editor";
new DisplayItemClassificationTypeProvider(_loadedStyleRegistry).RegisterAll();
try
{
foreach (var fontStyle in _editorFontSettings.FontStyles)
{
var highlightStyle = new HighlightingStyle();
if (fontStyle.IsForegroundSet)
{
highlightStyle.Foreground = new BrushConverter().ConvertFromString(fontStyle.Foreground) as Brush;
}
if (fontStyle.IsBackgroundSet)
{
highlightStyle.Background = new BrushConverter().ConvertFromString(fontStyle.Background) as Brush;
}
_loadedStyleRegistry.Register(new ClassificationType(fontStyle.Key, fontStyle.Description), highlightStyle, true);
}
}
catch (Exception)
{
loadSucceeded = false;
}
}
if (!loadSucceeded)
{
_loadedStyleRegistry = AmbientHighlightingStyleRegistry.Instance;
}
syntaxEditor.HighlightingStyleRegistry = _loadedStyleRegistry;
IHighlightingStyleRegistry registry = new HighlightingStyleRegistry();
new DisplayItemClassificationTypeProvider(registry).RegisterAll();
registry.Register(ClassificationTypes.Keyword, new HighlightingStyle(Brushes.HotPink));
registry.Register(ClassificationTypes.Comment, new HighlightingStyle(Brushes.Yellow));
codeEditor.HighlightingStyleRegistry = registry;
Please log in to a validated account to post comments.