Hi I'm new to AvalonEdit and was wondering if it is at all possible to change some Keywords foreground colour ruleset within C# code.
At the minute I have a xshd file with the main ruleset and another ruleset called customRuleset. and was wanting to in the c# code to change from the main keywords colour to the custom one.
<?xml version="1.0"?><SyntaxDefinition name="Custom Highlighting" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008"><Color name="Comment" foreground="Green"/><Color name="String" foreground="Red"/><!--Thisis the main ruleset.--><RuleSet><Span color="Comment" begin="//"/><Span color="Comment" multiline="true" begin="/\*" end="\*/"/><Span color="String"><Begin>"</Begin><End>"</End><RuleSet><!-- nested span for escape sequences --><Span begin="\\" end="."/></RuleSet></Span><Keywords fontWeight="bold" foreground="Red"><Word>if</Word><Word>else</Word><!--...--></Keywords><Keywords fontWeight="bold" fontStyle="italic" foreground="Red"><Word>AvalonEdit</Word></Keywords><!--Digits--><Rule foreground="Red">
\b0[xX][0-9a-fA-F]+# hex number| \b( \d+(\.[0-9]+)?#number with optional floating point| \.[0-9]+#or just starting with floating point)([eE][+-]?[0-9]+)?# optional exponent</Rule></RuleSet><RuleSet name="customRuleset"><Keywords fontWeight="bold" foreground="Yellow"><Word>if</Word><Word>else</Word><!--...--></Keywords></RuleSet></SyntaxDefinition>
C#// Load our custom highlighting definitionIHighlightingDefinition customHighlighting;
using (Stream s =typeof(Window1).Assembly.GetManifestResourceStream("AvalonEdit.Sample.CustomHighlighting.xshd")){if(s ==null)thrownewInvalidOperationException("Could not find embedded resource");
using (XmlReader reader =newXmlTextReader(s)){
customHighlighting =ICSharpCode.AvalonEdit.Highlighting.Xshd.HighlightingLoader.Load(reader,HighlightingManager.Instance);}}// and register it in the HighlightingManagerHighlightingManager.Instance.RegisterHighlighting("Custom Highlighting",newstring[{".cool"}, customHighlighting);