Setting background color

SyntaxEditor for WPF Forum

Posted 12 years ago by Tony Pulokas
Version: 11.2.0552
Avatar

I'm creating a custom language definition, and would like to easily set the background color (of non-highlighted text).  I'd prefer to KISS for now, as we're just prototyping, but I'd like to have something more available than just the text color (DefaultStyle).

Is there an easy way to say, set the background to: #FFF7E545 and the foreground to: #FF492E89?

Thanks!

-TPP

Comments (6)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Tony,

I believe you can just set the SyntaxEditor.Foreground and Background brushes for those things.


Actipro Software Support

Posted 12 years ago by Tony Pulokas
Avatar

I don't want to set the background of the whole editor, though - just for certain text segments (say, I want comments to have white text on a black background).  If I set the SyntaxEditor.Backgound = Brushes.Red; it makes the whole editor red.

I searched high-n-low - is there an overload for the DefaultStyle that takes an inline style in WPF that I can use instead of a Hex color #?

-TPP

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Tony,

For your comment example, you'd have to create/update the appropriate HighlightingStyle that is registered for the Comment classification type then.  If you look at our Highlighting Style Viewer QuickStart, you can see how that works, and can see it in action.


Actipro Software Support

Answer - Posted 12 years ago by Tony Pulokas
Avatar

So, for future reference, this is how I was able to accomplish it.  Not terribly difficult, but I am still scratching my head as to why I had to instantiate the HighlightingStyleRegistry.  I was assuming that I could pull the ClassificationTypes from my LangDef, but the HSR was always null.  By registering the ClassificationType in the HSR, the highlighting works as expected.  I traversed the object and could find no evidence of my ClassificationTypes that were already defined in my LangDef file.

Am I missing something there?  Is this just a case of me binding to the WPF with the .Register command?

Thanks for the prompt replies, it was very helpful.

-TPP

SyntaxLanguageDefinitionSerializer serializer = new SyntaxLanguageDefinitionSerializer();
string path = @"C:\Oasis\OCL.langdef";
ISyntaxLanguage language = serializer.LoadFromFile(path);
syntaxEditor.Document.Language = language;
BrushConverter bc = new BrushConverter();
// Create a custom Console Window registry
IHighlightingStyleRegistry consoleWindowRegistry = new HighlightingStyleRegistry();
consoleWindowRegistry.Description = "OCL Window";
syntaxEditor.HighlightingStyleRegistry = consoleWindowRegistry;
consoleWindowRegistry.Register(new ClassificationType("Comment"), new HighlightingStyle((Brush)bc.ConvertFrom("#FF008000"),(Brush)bc.ConvertFrom("#FFF7E746")));

My LangDef file looks like this:

<LanguageProject LanguageKey="OCL" LanguageDescription="OCL" OutputLanguageDefinition="False" OutputLanguageKey="CSharp" OutputNamespaceName="ActiproSoftware.Text.Languages.OCL" OutputPath="C:\.." Creator="" Copyright="...">
<!-- Classification types -->
<LanguageProject.ClassificationTypes>
<ClassificationType Key="Comment" DefaultStyle="#FF008000" />
...
</LanguageProject.ClassificationTypes>
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Tony,

If you aren't specifying a particular SyntaxEditor.HighlightingStyleRegistry (leaving it null) then it will just use the AmbientHighlightingStyleRegistry instance.  So I woudl guess that after you load your .langdef, if you would look in the AmbientHighlightingStyleRegistry, you would see an entry for the comment classification type.  Then you could just get the style for that classification type and modify it.


Actipro Software Support

Posted 12 years ago by Tony Pulokas
Avatar

Ah, there it is.  The AmbientHighlightingStyleRegistery.Instance exists, and is holding it.  Magic behind the scenes.  Thanks for that!

IHighlightingStyleRegistry asr = AmbientHighlightingStyleRegistry.Instance;
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.