diff --git a/README.md b/README.md index 660f792..1fefade 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,103 @@ -# How to configure custom language using WPF Syntax Editor? +# 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. -This sample holds the configuration of custom language - IronPython applied and loaded using [Syntax Editor](https://help.syncfusion.com/wpf/syntax-editor/getting-started). +## 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. +## 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. + +## 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. +