avaloniavs – XAML previewer for Avalonia
An unofficial XAML previewer and editing toolkit for Avalonia UI in VS Code. The preview
is drawn by your application's own Avalonia designer host, so what you see is what Avalonia renders. The same engine
as the Visual Studio extension,
behind a language server.
Not affiliated with or endorsed by AvaloniaUI OÜ. An early version (0.1.x): please report problems on
GitHub.
Getting started
- Install the .NET SDK 8 or later (
dotnet on PATH).
- Open the folder of an Avalonia application and an
.axaml file in it.
- Run Avalonia: Show Preview (or use the button in the editor title bar). The application is built the first
time if it has not been built yet.
Developed and tested with Avalonia 12.2 on Windows and Linux; macOS has not been tested.
Features
- Live preview beside the editor (
Avalonia: Show Preview, or the button in the editor title bar): rendered by the
application's own Avalonia designer host, updated as you type; pointer input is forwarded; Ctrl+Click (Cmd+Click)
an element to go to its markup; XAML errors with a link to the line. Toolbar: host application (when several can
host the document), zoom (also Ctrl+Wheel), theme variant, form factor (phone, tablet, 720p ...) with rotation.
avaloniavs.preview.method: html shows the designer host's own web page in the browser instead.
- Completion, hover, go to definition, diagnostics (AVS001...) with quick fixes, refactorings, outline/breadcrumbs,
colour swatches, markup-extension colouring, new event handlers in the code-behind.
- "S" after elements that styles of the document apply to (hover: the styles and setters; Ctrl+Click: go to the style).
- Avalonia Toolbox view (Explorer): the controls of the application and its packages; click to insert at the caret.
Avalonia: Insert Control... does the same from the keyboard.
Drag an item into the editor, or use its "Place in Preview" button and then click in the preview: the control is
added to the panel under that point, right after the element that was clicked.
- Move and resize in the preview: Ctrl+Click selects an element (a frame with handles; Esc deselects). Drag a handle
to set its Width / Height; drag the frame to move it: Canvas.Left/Top in a Canvas, another place among its
siblings in a StackPanel / WrapPanel / DockPanel (drop it onto the sibling), its Margin anywhere else.
- Tooltips show pictures: the Grid cell of Grid.Row/Column, the sides of a Margin/Padding/CornerRadius, path data, images.
Avalonia: New Item... (also in the Explorer context menu): Window, UserControl, TemplatedControl, Styles,
ResourceDictionary, value converters.
- The whole document is classified (elements, properties, attached properties, events, directives, values, markup
extensions).
Avalonia: Select Color Scheme... (avaloniavs.colorScheme) colours them: "Avalonia", "Classic XAML"
(the colours of Visual Studio's XAML editor), or the editor theme.
- The application is built automatically when the preview needs it and it was not built yet
(
avaloniavs.preview.autoBuild); the Build button of the preview rebuilds it.
- Snippets for XAML (
grid, coldefs, rowdefs, style, setter, datatemplate, designdata) and C#
(styledProperty, directProperty, attachedAvaloniaProperty, avaloniaRoutedEvent).
Snippets and item templates are generated from the Visual Studio extension's files (npm run assets).
Development
The source is at https://github.com/TomoyukiNakama/avaloniavs (folder vscode).
npm install
npm run server # publishes the language server into ./server
npm run compile
code --extensionDevelopmentPath=. ../samples/SampleApp # or F5 in VS Code
The custom protocol (avalonia/preview/*) is documented in src/AvaloniaVs.Server/PreviewManager.cs.
Testing
test/integration.js runs inside a real VS Code against samples/SampleApp (build it and run npm run server first):
code --extensionDevelopmentPath=. --extensionTestsPath=./test/integration.js ../samples/SampleApp
Set AVALONIAVS_TEST_OUT=<file> to get the result of each step. The server itself is covered by
tests/AvaloniaVs.Previewer.Tests/ServerTests.cs, which also passes on Linux (mcr.microsoft.com/dotnet/sdk:10.0
with libfontconfig1 installed).
Package with npx @vscode/vsce package.
| |