Avalonia 0.9.0 Release

Published
Friday, 13 December 2019
Category
Release
Author
Dan Walmsley

We are pleased to announce that Avalonia 0.9.0 has been released.

0.9 is a huge update, it has been extensively tested and brings some great new features and improvements.

Compiled XAML

In previous releases, XAML was parsed at runtime and it had significant runtime overhead as well as some errors could cause runtime crashes.

For this release, we have built a XAML compiler that parses XAML at build time and compiles it to MSIL.

This greatly improves runtime performance, application startup times and allows errors to be caught at build time instead of runtime.

The new XAML compiler also allows the debugger to step into XAML code: video

It will give you a proper stack trace when something got broken at run time.

OSX / Linux Native Menus

OSX places a menu that is permanently at the top of the screen. The first item of which the title matches the application name, it is a global application menu, and is displayed regardless of the selected window or if the application is minimised.

For applications to feel like they belong on OSX, they would need to implement these menus. The same applies to some window managers on Linux, although it is less common.

Avalonia will now create this menu for you, and generate the standard menu items that OSX users expect. OSXAppMenu

If you want to customise this menu, then you can do so by declaring a Native Menu in your Application.xaml file like so.

<Application>
  <NativeMenu.Menu>
    <NativeMenu>
      <NativeMenuItem Header="About MyApp" Command="{Binding AboutCommand}" />
    </NativeMenu>
  </NativeMenu.Menu>
</Application>

The consequence of this is that the Application class now has a DataContext property, where you can assign a ViewModel and bind to properties, just like any other control in Avalonia.

The Window menus of course are window specific, and can be declared like:

<Window>
  <NativeMenu.Menu>
    <NativeMenu>
      <NativeMenuItem Header="File">
        <NativeMenuItem.Menu>
          <NativeMenu>
            <NativeMenuItem Header="Open" Command="{Binding OpenCommand}"/>
            <NativeMenuItemSeperator/>
            <NativeMenuItem Header="Recent">
              <NativeMenuItem.Menu>
                <NativeMenu/>
              </NativeMenuItem.Menu>
            </NativeMenuItem>
            <NativeMenuItemSeperator/>
            <NativeMenuItem Header="Quit Avalonia" Command="{Binding CloseCommand}" Gesture="CMD+Q"/>
          </NativeMenu>
        </NativeMenuItem.Menu>
      </NativeMenuItem>
      <NativeMenuItem Header="Edit">
        <NativeMenuItem.Menu>
          <NativeMenu>
            <NativeMenuItem Header="Copy"/>
            <NativeMenuItem Header="Paste"/>
          </NativeMenu>
        </NativeMenuItem.Menu>
      </NativeMenuItem>
    </NativeMenu>
  </NativeMenu.Menu>
</Window>

To display this menu inside your window on platforms with more traditional menus you can use <NativeMenuBar/> control. Just place it where your menu should be and it will display it when needed automatically.

As you can see, native menus support gestures just like a normal MenuItem would.

OSXWindowMenu

It is currently disabled on Linux by default and can be enabled via

.With(new X11PlatformOptions
{
    UseDBusMenu = true
})

Optional Managed File Dialogs

Some operating systems may not have their own File dialogs, or you may prefer to use Avalonia's own file dialog for consistent UI.

ManagedDialogs

You can configure Avalonia to use the managed dialog by adding to the appbuilder like so:

AppBuilder.Configure<App>()
.UsePlatformDetect()
.UseManagedSystemDialogs();

If you wish the file dialog to be hosted inside your own window, where you control the chrome, colour scheme, title, icon, etc you can also use...

.UseManagedSystemDialogs<AppBuilder, MyCustomWindowType>();

ItemsRepeater

The ItemsRepeater control has been ported from UWP. This control is a high-performance virtualized list that supports many different layouts (via Attached Layouts), smooth scrolling and grouping.

In the long-term we intend to use ItemsRepeater to implement Avalonia's ItemsPresenter so that all ItemsControls can take advantage of these great features.

New Grid and GridSplitter

Now that WPF has been opensourced we have directly ported Grid and Grid Splitter from those repositories. This means you can now expect 100% identical behavior of these fundamental controls. In December last year, Microsoft announced that WPF would be open sourced. In the intervening months, the source code was published and we have been able to take advantage of this by porting Grid and GridSplitter from WPF. This means you can now expect 100% identical behavior between Avalonia and WPF of these fundamental controls

Performance Improvements

It's worth mentioning that there have been many improvements to Avalonia especially to improve performance, reduce the amount of memory and improve speed. Many projects are now able to run smoothly on embedded platforms like Raspberry PI.

KMS/DRM/GBM backend for Linux

We now support OpenGL accelerated rendering when running directly on top of the Linux kernel without XOrg or Wayland compositor. The input backend was changed to use libinput. You can take a look at the demo video on desktop hardware here: video

This effectively allows you to create kiosk-style applications, where there is nothing but Linux kernel and your application running on the hardware.

Experimental touch event support

It's currently disabled by default, but if you have touch-capable monitor, you can play around with it by adding

.With(new X11PlatformOptions
{
    EnableMultiTouch = true
})
.With(new Win32PlatformOptions
{
    EnableMultitouch = true
})

to your application builder. Touch event are now handled as proper touch events thanks to adopting UWP model of pointer events with separate pointer device for each touch contact. We've also added touch scrolling support to our ScrollViewer.

Production Ready

Many people come and ask, is Avalonia production ready? The answer is YES! There are now several applications built on Avalonia with large user bases. We are starting to see a number of commercial products that are now being ported to Avalonia, and we hope this trend will continue!

The teams behinds these projects have been involved with testing this release.

For this reason we will be maintaining a branch of the 0.9 release with only bug fixes. So 0.9 will be maintained and supported even as we start the development of the next major version of Avalonia.

In addition, we're pleased to announce that we have formed a company to provide support contracts and custom development around Avalonia. The idea is to make Avalonia development sustainable in the long term: we're really pleased with what we've managed to get done with only volunteers but we feel we're at the point where we need some full-time developers on the project. We're still working out the details of pricing etc, but if you're interested or need more urgent support drop us a line. (team@avaloniaui.net)

Getting started

Follow instructions here.

Special Thanks

This release has only been possible due to the dedicated work of many people, notably grokys, jkoritzinsky, kekekeks, danwalmsley, jmacato, marchingcube, wieslawsoltes, gillibald and many others.

The best way to support Avalonia is to get involved, implement a feature, fix a bug or help test. See contributing for information on how to get started.

Otherwise you can sponsor Avalonia financially via OpenCollective.

We hope you enjoy developing with Avalonia - please let us know what you are building!

danwalmsley