If you set the Dark theme before setting the language, the code fails to apply the correct C# colors:
public Form1()
{
// Register display item classification types
new DisplayItemClassificationTypeProvider().RegisterAll();
// Load Dark Theme
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFormsApp4.Dark.vssettings"))
{
if (stream != null)
AmbientHighlightingStyleRegistry.Instance.ImportHighlightingStyles(stream);
}
// Create syntax editor
InitializeComponent();
// Set Language to C#
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFormsApp4.CSharp.langdef"))
{
if (stream != null)
{
SyntaxLanguageDefinitionSerializer serializer = new SyntaxLanguageDefinitionSerializer();
syntaxEditor1.Document.Language = serializer.LoadFromStream(stream);
}
}
}
If you change it so the Dark theme is applied after setting the language it works OK.
Do I need to call something else after setting the langauge to make the above work?
I think this is a common scenario as setting the Dark theme at application startup makes more sense than after you have created a new view containing the syntax editor.