16

Enrich Your WPF Apps with the New SyntaxEditor Control

 4 years ago
source link: https://www.tuicool.com/articles/zUzMva2
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Show a block of highlighted code, display a custom language or add a complete code editor in your app – our syntax editor gives you plenty of opportunities for your applications. 

You know our shiny  Telerik UI for WPF Demos Application , right? If you don’t, this is a robust WPF app, showcasing all of the over 140 UI controls of the  Telerik UI for WPF component suite . Each of the components is presented by a handful of demos, all of them accompanied by their source code, so it is super easy to see how to use the different control features. 

How do we visualize the source code files? It’s via theRadSyntaxEditor control. You wanted it included in our WPF suite and we delivered it. Now you can implement source code editors and viewers in your desktop applications, in any language! (:clap: :clap: :clap:) 

aQZbUzB.png!web

Before going into the features let's make an important note that the RadSyntaxEditor is Beta in the R3 2019 release, and we really want to hear the scenarios you want it to cover for your applications in the future. This way we will surely deliver an outstanding official version in January 2020.

Quick Start

To get started with the syntax editor, add it in XAML and then in code set its Document property to refer a file. The last step is to register a suitable tagger class to color the code properly.

<Grid>

   <telerik:RadSyntaxEditor x:Name="syntaxEditor"  />

</Grid>

public MainWindow()

{

    StyleManager.ApplicationTheme = new FluentTheme();

    InitializeComponent();

    Uri filePathUri = new Uri("/SyntaxEditor_Design;component/Test/CSharp.cs", UriKind.RelativeOrAbsolute);

    using (Stream stream = Application.GetResourceStream(filePathUri).Stream)

    {

        StreamReader reader = new StreamReader(stream, Encoding.UTF8);

        this.syntaxEditor.Document = new TextDocument(reader);

    }

    CSharpTagger cSharpTagger = new CSharpTagger(this.syntaxEditor);

    this.syntaxEditor.TaggersRegistry.RegisterTagger(cSharpTagger);

So in 10 lines of code, you get a code editor of your C# file in a modern looking Fluent theme:

7nqYVjU.png!web

Now lets look inside the fridge.

What's in the Toolbox?

Syntax Highlighting

The syntax editor knows how to detect and color keywords, comments and regions in the following well-known languages in the .NET world: C#, VB, JS, SQL. Also, it recognizes the different parts in an XML-based source code text, so it is perfectly designed for highlighting XML-based language files - XML, XAML, HTML.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK