We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to configure the syntax coloring for custom Language?

Platform: WPF |
Control: EditControl |
Published Date: September 19, 2018 |
Last Revised Date: September 20, 2018 |
.NET Framework: 4

The EditControl has a built-in syntax highlighting support for the following languages

 

  1. C#
  2. Visual Basic
  3. XAML
  4. XML
  5. SQL

 

It also allows the user to create Custom Language configurations to apply syntax highlighting. It can be achieved by following step.

 

Step 1: Add EditControl into application.

 

Code Example: [Xaml]

 

 

Step 2: Create custom language class inherited from any one of EditControl  base classes.

 

For Example,

 

We have created the PowershellLanguage [custom language] class inheriting from ProceduralLanguageBase and set basic properties of the language. The following code demonstrates the same.

 

Code Example: [C#]

 

 

Step 3: Create a Format collection.

 

This section helps you to initialize the Format strings. The Format assigns the syntax coloring for the keywords, text, comment tag, etc. The following code demonstrates the same.

 

Code Example: [Xaml]

 

 

Note: Every format contains the attributes such as name, font, fore color, font color, back color, style, weight, underline, and line color.

 

Step 4: Create a Lexem collection.

 

The Lexem contains rules for parsing the text. There are two attributes to specify the format of the lexem.

 

  1. LexemType: Used for standard predefined types of the lexems.
  2. FormatName: Used to assigns the syntax coloring for the keywords, text, comment tag, etc.

 

The following code demonstrates the same.

 

Code Example: [Xaml]

 

 

Note: Lexems are used to initialize the lexem option and to define the keyword, operands, number, string, etc.

 

Step 5: Assign the lexem and Format properties to Custom Language.

 

The following code demonstrates the same.

 

Code Example: [C#]

 

 

Step 6: Apply the created custom language to Editcontrol language.

 

The following code demonstrates the same.

 

Code Example: [C#]

 

 

Screenshot

 

Figure: EditControl configured with Powershell language.

 

Sample:  PowershellLanguageExample

 

 

 

 

 

 

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile