From 7cb9090a73bd67ca607fe5b2c1654fa017aef688 Mon Sep 17 00:00:00 2001 From: KrithikaGanesan Date: Fri, 24 Oct 2025 14:09:07 +0530 Subject: [PATCH 1/2] 985360: Updated ReadMe file of this repository --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 660f792..9f5a367 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ -# How to configure custom language using WPF Syntax Editor? +# How to Configure Custom Language Using WPF Syntax Editor? +This repository demonstrates how to configure and apply a custom language definition—specifically IronPython—in the WPF [Syntax Editor](https://help.syncfusion.com/wpf/syntax-editor/getting-started) control provided by Syncfusion. The WPF Syntax Editor is a powerful text editor control that supports syntax highlighting, code editing, and parsing for various programming languages. It is highly customizable and supports defining your own language grammars using XML-based configuration files. -This sample holds the configuration of custom language - IronPython applied and loaded using [Syntax Editor](https://help.syncfusion.com/wpf/syntax-editor/getting-started). +In this sample, we show how to: + +- Create a custom language definition file for IronPython. +- Load and apply the custom language to the Syntax Editor at runtime. +- Highlight keywords, comments, strings, and other syntax elements specific to IronPython. +- Integrate the Syntax Editor into a WPF application with minimal setup. + +This approach is ideal for developers building code editors, IDEs, or any application that requires syntax-aware text editing. By using custom language configurations, you can tailor the editor to support domain-specific languages or scripting environments. ![Syntax Editor with custom language](Images/output.png) From 5d7d6ecd66ba86b421387a05742cee39de031a68 Mon Sep 17 00:00:00 2001 From: Manivannan-E <92844213+Manivannan-E@users.noreply.github.com> Date: Thu, 27 Nov 2025 14:44:18 +0530 Subject: [PATCH 2/2] Update README.md --- README.md | 106 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 98 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9f5a367..1fefade 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,103 @@ -# How to Configure Custom Language Using WPF Syntax Editor? -This repository demonstrates how to configure and apply a custom language definition—specifically IronPython—in the WPF [Syntax Editor](https://help.syncfusion.com/wpf/syntax-editor/getting-started) control provided by Syncfusion. The WPF Syntax Editor is a powerful text editor control that supports syntax highlighting, code editing, and parsing for various programming languages. It is highly customizable and supports defining your own language grammars using XML-based configuration files. +# How to Configure a Custom Language in WPF Syntax Editor +This example demonstrates how to configure and apply a custom language definition (Python) in the Syncfusion WPF Syntax Editor control. The Syntax Editor supports syntax highlighting, code editing, and parsing for various languages. You can define your own language grammar using LexemCollection and FormatsCollection for custom syntax rules. -In this sample, we show how to: +## Why This Is Useful +- **Custom Language Support**: Add domain-specific or scripting languages. +- **Syntax Highlighting**: Highlight keywords, comments, operators, and literals. +- **MVVM Integration**: Apply language configuration dynamically at runtime. -- Create a custom language definition file for IronPython. -- Load and apply the custom language to the Syntax Editor at runtime. -- Highlight keywords, comments, strings, and other syntax elements specific to IronPython. -- Integrate the Syntax Editor into a WPF application with minimal setup. +## Key Steps +- Define _FormatsCollection_ for syntax highlighting styles. +- Define _LexemCollection_ for language tokens and rules. +- Apply the custom language to the EditControl using the _CustomLanguage_ property. -This approach is ideal for developers building code editors, IDEs, or any application that requires syntax-aware text editing. By using custom language configurations, you can tailor the editor to support domain-specific languages or scripting environments. +## Code Example +**XAML** +```XAML + + + + + + + + + + + + + + + + + + + + + + + + + + + + +``` +**ViewModel (C#)** +```C# +public class CustomLanguageViewModel : NotificationObject +{ + public ICommand EditLoadedCommand { get; } + public string DocumentSource { get; set; } + public Languages Language { get; set; } + public FontFamily SelectedFont { get; set; } + + public CustomLanguageViewModel() + { + DocumentSource = @"Data\syntaxeditor\PythonSource.py"; + SelectedFont = new FontFamily("Verdana"); + Language = Languages.Custom; + EditLoadedCommand = new DelegateCommand(ExecuteEditLoaded); + } + + private void ExecuteEditLoaded(object obj) + { + var editControl = obj as EditControl; + var customLanguage = new PythonLanguage(editControl) + { + Lexem = (LexemCollection)Application.Current.Resources["pythonLanguageLexems"], + Formats = (FormatsCollection)Application.Current.Resources["pythonLanguageFormats"] + }; + editControl.CustomLanguage = customLanguage; + } +} +``` + +## Notes +- Requires Syncfusion WPF Syntax Editor NuGet package. +- You can extend this approach for other languages or domain-specific syntax. +- Use LexemCollection for token definitions and FormatsCollection for styling. + +## Output ![Syntax Editor with custom language](Images/output.png) + +## Reference +For more details refer the Syncfusion WPF Syntax Editor Documentation for [custom language](https://help.syncfusion.com/wpf/syntax-editor/language-support/custom-language-support) support. +