Visual Studio Code Wpf



The WPF Syntax Highlighting and Code Editor Control is a powerful text editor control similar to the Microsoft Visual Studio editor. It provides built-in syntax highlighting and code editing experience for popular languages. Allows users to create custom syntax highlighting of keywords and operators of their own language. It offers all essential features end users expect, like syntax highlighting, editing, undo, redo, cut, copy, paste, IntelliSense, line numbering, highlighting modified lines, custom language configuration, and more.

WPF is based on.Net environment, it means it is a managed code and theoretically can be written with any.Net based language such as Visual C#, VB.Net and Managed C. WPF introduced with.Net 3.0 with few other important technologies such as Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF), but here we are going to. The XAML code editor in the Visual Studio IDE includes all the tools you need to create WPF and UWP apps for the Windows platform, and for Xamarin.Forms. This article outlines both the role the code editor plays when you develop XAML-based apps, and the features that are unique to the XAML code editor in Visual Studio 2019. Windows Presentation Foundation (WPF) and XAML combine into a rich presentation system for building Windows desktop applications with visually stunning user experiences that incorporate UI, media, and complex business models. One thing that I have always been hoping for as a XAML developer is deeper connectivity between the XAML and the View-Model. We have seen increased IntelliSense in this area, but with the release of Visual Studio 2019 v16.9 comes code generation from XAML! That is right, you can now have Visual Studio automatically create your properties.

Features and Benefits of Syntax Highlighting and Code Editor Control

Syntax highlighting

Provides syntax highlighting for procedural programming and markup languages. Also allows users to customize built-in languages.

Built-in language highlighting - Offers built-in syntax highlighting and code editing experiences for the following languages:

  • C#
  • VB.NET
  • XML
  • XAML
  • SQL
Studio

Configure custom language - Allows users to create custom syntax highlighting of keywords and operators of their own language.

IntelliSense

IntelliSense displays a pop-up with a list of code completion options to speed up coding by reducing typos and other common mistakes. Allows users to get the list of code completion words from any external assembly reference.

Code outlining

Displays code blocks in tree structure and allows users to expand and collapse the code blocks interactively for readability. WPF Syntax Editor automatically chooses where to create outlines for built-in languages. Also allows users to create outline for their own syntax highlighting.

Comment and uncomment codes

Support to comment or uncomment codes with the help of comment option of the WPF Syntax Editor. Allows users to select the required block of codes to comment. WPF Syntax Editor comments the current line when there is no selection.

Tracking changes

Visual Studio Code Xaml Design

Display markers at the start of lines modified after the file is loaded or after the last file save operation.

Design IDE

Studio

Supports built-in commands to design development environment for popular languages. Provides commands for file (editing operations such as new, open, save, print, indent, and more).

Undo and redo

Include keyboard and context menu support for undo and redo operations that erase the last change in a document and reinsert it.

Clipboard operations

Provides clipboard operations such as cut, copy, and paste using keyboard and context menu.

Selection

Allows users to select the text interactively using mouse and keyboard. Users can select the text in touch environment by double tapping the text and extending the selection using touch pointer.

Search

Find occurrences of specified text with constraints such as match case, match whole words, and search directions. Allows users to search text in a specific scope like current document or within selected content.

Find and Replace

Replace the specified text with the replacement text as per the conditions specified. Includes options to replace the first occurrence or all occurrences of the search text.

Line numbers

Displays the line number at the start of a line for the users to identify the current number.

Visual Studio Code Wpf Tutorial

Highlight line

Support to highlight a particular line with different background color. It helps users differentiate a specific line from the non-highlighted lines.

Navigation

Navigation to the next character or word, or the start or end of a line can be done easily through keyboard. Allows users to jump to specific lines using go to line dialog.

Context tooltip

Provides built-in interactive tooltips that appear automatically when the pointer is placed over a collapsed block of text.

Context menu

Provides built-in context menu support with editing, and selection operations such as cut, copy, paste and select all, and much more.

Read-only

Support to use WPF Syntax Editor as viewer control in order to view files and restrict code editing.

Style

Provides a rich set of built-in themes inspired by popular interfaces such as Visual Studio, Microsoft Office, and Expression Blend.

Print

Support to print syntax editor content either by using the print option from the print preview or programmatically. The print preview window allows users to choose page orientation, print entire document or the specific page, and number of copies to print.

Localization

The WPF Syntax Editor supports localization to translate the static text to any desired language.

Related Links

About Syncfusion

Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion has more than 23,000 customers and more than 1 million users, including large financial institutions, Fortune 500 companies, and global IT consultancies.

Today we provide 1600+ controls and frameworks for web (Blazor, ASP.NET Core, ASP.NET MVC, ASP.NET WebForms, JavaScript, Angular, React, Vue, and Flutter), mobile (Xamarin, Flutter, UWP, andJavaScript), and desktop development (WinForms, WPF, WinUI(Preview), and UWP, and Flutter). We provide ready-to-deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software.

sales@syncfusion.com | www.syncfusion.com | Toll Free: 1-888-9 DOTNET

One thing that has been recently announced by Microsoft is the availability of .NET Core 3. With it, you will be able to create WPF and Winforms apps with .NET Core. And one extra bonus is that both WPF and Winforms are being open sourced. You can check these in https://github.com/dotnet/wpf and https://github.com/dotnet/winforms.

The first step to create a .NET Core WPF program is to download the .NET Core 3.0 preview from https://dotnet.microsoft.com/download/dotnet-core/3.0. Once you have it installed, you can check that it was installed correctly by open a Command Line window and typing dotnet –info and seeing the installed version:

:

With that in place, you can change the current folder to a new folder and type

This will create a new .NET Core 3.0 WPF project and will compile and run it. You should get something like this:

If you click on the Exit button, the application exits. If you take a look at the folder, you will see that it generated the WPF project file, App.xaml and App.xaml.cs, MainWindow.xaml and MainWindow.xaml.cs. The easiest way to edit these files is to use Visual Studio Code. Just open Visual Studio Code and go to menu File/Open Folder and open the folder for the project. There you will see the project files and will be able to run and debug your code:

A big difference can be noted in the csproj file. If you open it, you will see something like this:

That’s very simple and there’s nothing else in the project file. There are some differences between this project and other types of .NET Core, like the console one:

  • The output type is WinExe, and not Exe, in the console app
  • The UseWPF clause is there and it’s set to true

Now, you can modify and run the project inside VS Code. Modify MainWindow.xaml and put this code in it:

Now, you can compile and run the app in VS Code with F5, and you will get something like this:

If you don’t want to use Visual Studio Code, you can edit your project in Visual Studio 2019. The first preview still doesn’t have a visual editor for the XAML file, but you can edit the XAML file in the editor, it will work fine.

Porting a WPF project to .NET Core

To port a WPF project to .NET Core, you should run the Portability Analyzer tool first, to see what problems you will find before porting it to .NET Core. This tool can be found here. You can download it and run on your current application, and check what APIs that are not portable.

I will be porting my DiskAnalisys project. This is a simple project, that uses the File.IO functions to enumerate the files in a folder and uses two NuGet packages to add a Folder Browser and Charts to WPF. The first step is to run the portability analysis on it. Run the PortabilityAnalizer app and point it to the folder where the executable is located:

When you click on the Analyze button, it will analyze the executable and generate an Excel spreadsheet with the results:

Visual Studio Code Wpf Application

As you can see, all the code is compatible with .NET Core 3.0. So, let’s port it to .NET Core 3.0. I will show you three ways to do it: creating a new project, updating the .csproj file and using a tool.

Upgrading by Creating a new project

This way needs the most work, but it’s the simpler to fix. Just create a new folder and name it DiskAnalysisCorePrj. Then open a command line window and change the directory to the folder you’ve created. Then, type these commands:

These commands will create the WPF project, add the two required NuGet packages and run the default app. You may see a warning like this:

This means that the NuGet packages weren’t converted to .NET Core 3.0, but they are still usable (remember, the compatibility report showed 100% compatibility). Then, copy MainWindow.xaml and MainWindow.xaml.cs from the original folder to the new one. We don’t need to copy any other files, as no other files were changed. Then, type

and the program is executed:

Converting by Changing the .csproj file

This way is very simple, just changing the project file, but can be challenging, especially for very large projects. Just create a new folder and name it DiskAnalysisCoreCsp. Copy all files from the main folder of the original project (there’s no need of copying the Properties folder) and edit the .csproj file, changing it to:

Then, type

and the program is executed.

Converting using a tool

The third way is to use a tool to convert the project. You must install the conversion extension created by Brian Lagunas, from here. Then, open your WPF project in Visual Studio, right-click in the project and select “Convert Project to .NET Core 3”.

That’s all. You now have a NET Core 3 app. If you did that in Visual Studio 2017, you won’t be able to open the project, you will need to compile it with dotnet run, or open it in Visual Studio code.

Visual Studio Code Wpf

Conclusions

Visual Studio Code Wpf

As you can see, although this is the first preview of WPF .NET Core, it has a lot of work done, and you will be able to port most of your WPF projects to .NET Core.