The release of the first beta cross-platform XAML UI-toolkit Avalonia

    The release of the first beta version of Avalonia .


    Avalonia is a cross-platform .NET UI toolkit inspired by WPF technologies and distributed under the MIT license. It fully supports .NET Core 2.0, XAML, data bindings, lookless controls, and much more. Avalonia allows you to write C # applications for Windows, Linux and Mac OS X. The ability to run on iOS and Android is in an experimental state.



    This version is stable and has every right to be called a beta: the toolkit does not fall apart in the hands and has a decent basic set of controls (see video). It created two fairly large open source applications: AvalonStudio - a cross-platform IDE for development in C # and C ++ and Core2D - an editor of 2D diagrams and diagrams.


    The easiest way to take it and start using it is to install our extension for Visual Studio or use the templates for dotnet new . Examples are available for review in the main repository .


    In the process of preparing the release, a number of important changes took place:


    • Migrating to the .NET Standard 2.0 Platform
    • The old slow XAML parser was replaced by Portable.Xaml , which made it possible to speed up the launch of AvalonStudio from 25 to 7 seconds (on an SSD or on an HDD with a "hot" file cache).
    • Removed old and incompatible with .NET Core Cairo and gtk-sharp backends. Instead, they now use Skia (a 2D rendering library from Google Chrome) and their own GTK3 binders.
    • Instead of the fork, ReactiveUI 8 switched to the official version, since it began to support .NET Standard.
    • The site avaloniaui.net has been launched , on which documentation is available. In the future, articles will be added there.

    Key features in the release


    Retained - separate stream rendering mode


    Previously, the window was completely redrawn with every change. This approach is simple and reliable, but extremely inefficient. Instead, it was implementedDeferredRenderer that converts the calls of our rendering API to a window scene graph . A separate thread searches for changed sections in the graph and redraws only them. In addition to removing the load from the UI stream, this allows you to add optimizations, highlighting portions of the window in cached layers.


    The new rendering infrastructure has significantly improved performance, especially in cases with animations. It also gave us the opportunity to implement well-working hit-testing.


    If you have problems using the new infrastructure, the old implementation is ImmediateRendererleft for compatibility.


    MonoMac backend for OS X


    Since GTK2 / GTK3 are heavy libraries (~ 60MB), and were used only for wrapping over the native Carbon API, we implemented the Cocoa backend using a specially built .NET Standard MonoMac. This simplified the assembly of bundles and allowed using native file dialogs for OS X instead of the "universal" ones provided by GTK.


    Syntactic sugar for RelativeSource


    Earlier, as in WPF, bindings to other controls were carried out through RelativeSource. This syntax is very verbose: for example, binding text to a property of a Tagparent element looks something like this:



    The new syntax allows you to rewrite it like this:



    In addition to the keyword $parent, the following features are added:


    AbbreviationFull form
    $selfMode = Self
    $parentMode = FindAncestor; AncestorLevel = 1
    $parent[Level]Mode = FindAncestor; AncestorLevel = Level +1
    $parent[ns:Type]Mode = FindAncestor; AncestorType = ns:Type
    $parent[ns:Type; Level]Mode = FindAncestor; AncestorType = ns:Type; AncestorLevel = Level + 1

    * ns:Type- namespace: Type, e.g. Borderorlocal:MyControl


    Drawing


    Drawing- A convenient presentation for vector graphics such as icons used in WPF. Visual Studio Image Library provides hundreds of icons in this format. Their use improves performance, since all parts of the image are one element of the visual tree .


    Now Avalonia has support for this format. Our standard control Imageis not yet able to work with them, but you can already use it DrawingPresenter.


    StaticResource and DynamicResource


    The new version adds the usual WPF / UWP Control.Resources, StaticResourceand DynamicResource.


    The implementation exactly matches the similar functionality in WPF / UWP. Previously, all resources were tied to styles and it was proposed to use them to access them {StyleResource}. Now each control has its own dictionary of resources that are inherited from the element tree. The markup extension has {StyleResource}been removed: now it should be used instead {DynamicResource}.


    Binding commands to methods


    I think everyone has an implementation in the project ICommandthat accepts a delegate in the constructor. In order not to produce unnecessary entities, binding directly to the methods of the view model is added to the framework itself.


    public class ViewModel
    {
        public void ButtonClicked()
        {
            Console.WriteLine("Hooray!");
        }
    }


    Calendar


    He was dragged from the Silverlight Toolkit . Now you can select the dates.


    WPF Integration


    In the new version, the components of Avalonia can be seamlessly integrated into applications on WPF. This became possible due to the fact that the layout systems in Avalonia and WPF are almost identical, and Direct2D with the help of black magic can render directly into the one sharpened for Direct3D 9 D3DBitmap. You can see the demo here .


    Curiously, thanks to the use of Direct2D with such integration on complex scenes, the difference in performance can reach two orders of magnitude in favor of Avalonia. If you have inhibitory control under WPF, it might make sense to try porting and embedding it back.


    New .NET Core Preview Preview Infrastructure


    The previous version of the preview for the studio was written in three days with cutting all possible angles. As a result, it turned out to be tied to the Win32 API, a complete .NET Framework and Windows Forms. Now, instead of it, a smarter system was invented, with TCP / IP communication and the ability to transfer bitmaps instead of direct window integration in Visual Studio. This allowed us to properly preview XAML in projects under .NET Core and, more importantly, paved the way for support in other IDEs. In particular, support has already been added to AvalonStudio. Work is underway on a plug-in for Visual Studio Code, but it is difficult: this IDE is built on advanced and progressive web technologies and requires a separate language-server, binding around MSBuild and transferring pictures via WebSocket.


    In addition prevyuvera infrastructure "remote" widgets can be useful somewhere else, so the classes RemoteServerand RemoteWidgetare available for use.


    Other improvements


    A complete list can be found here , and below are the most interesting points:


    • #894Buttons turn off if property binding Commandreturnednull
    • #1085 Added FindAncestor
    • #1086 ReactiveUI updated to eighth version
    • #1128 The button has a property IsPressed
    • #1133For tooltip implemented IsOpen, Placement,Offset
    • #1145 Moved to .NET Standard 2.0
    • #1146 Property implemented for window ShowTaskbarIcon
    • #1150 Implemented screen information access API
    • #1174BurnedRemoved support for GTK2 and Cairo support
    • #1175Realizovanna Orientationand IsIndeterminatehave a progress indicator
    • #1253 PageSlide animation implemented in vertical orientation
    • #1265 Реализована поддержка трёх состояний для ToggleButton, CheckBox и RadioButton (серенькое ни-да-ни-нет)
    • #1273 Облегчили настройку логирования при настройке AppBuilder

    Изменения, ломающие совместимость


    Хорошая новость: мы их теперь отслеживаем и иногда даже документируем.
    Плохая новость: они есть.


    BuildAvaloniaApp для превьювера.


    Для работы новому превьюеру необходимо получить информацию у самого приложения. Для этого в классе с точкой входа (обычно Program.cs прямо рядом с Main) должен быть реализован метод BuildAvaloniaApp, примерно такой:


    static void Main(string[] args)
    {
        BuildAvaloniaApp().Start();
    }
    public static AppBuilder BuildAvaloniaApp() =>
        AppBuilder.Configure()
                  .UsePlatformDetect()
                  .LogToDebug();

    Без него предварительный просмотр работать не будет. Такие дела.


    DataContextChanging и DataContextChanged


    Заменены на OnDataContextBeginUpdate and OnDataContextEndUpdate.


    Расширения разметки Static и Type


    Replaced by x:Staticand x:Type, you need to add space xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"to the root element of the XAML file. For standardization.


    StyleResource


    StyleResourcereplaced by StaticResourceand DynamicResource, as in all normal XAML frameworks. StaticResourceand DynamicResourceare looking in Control.ResourcesandStyle.Resources .


    Mouse device


    Removed one of the global variables - MouseDevice. The mouse is now available at the top level: call GetVisualRootand cast the result to IInputRoot. This is because global variables and the service locator are evil.


    var pos = (_control.GetVisualRoot() as IInputRoot)?.MouseDevice?.Position ?? default(Point);

    How to start using?


    Download the addition to the Studio and create a project from the template. There is no complete documentation yet, so experience with WPF or UWP is needed.


    Also popular now: