Skip to main content

Samples

Avalonia has tons of great samples to help you get started!

Model-View-ViewModel (MVVM)

Basic MVVM

Use the MVVM pattern to receive and process text input by the user.

Binding and converters

Convert a date to a string value, and thereby calculate the age of a person.

Value converter

Incorporate a converter inside your binding to calculate a new value for the View.

Commands

How to invoke methods in your ViewModel from your user interface using commands.

Data validation

Validate properties and display an error message if the values are invalid.

Dialogs

Show dialogs using ReactiveUI interactions.

Dialog manager

Create a dialog manager service that helps you show dialogs in your app.

Data templates

Basic DataTemplate

Use DataTemplates to control how your data is displayed.

FuncDataTemplate

Create an advanced DataTemplate in code with a FuncDataTemplate.

IDataTemplate

Implement IDataTemplate in your own class to have full control over your DataTemplates.

Styles and drawing

Button customization

Customize the style of a button by creating reusable styles.

Making lists

Create lists of data using bindings and the ListBox control.

Native menus

Use native menus in your Avalonia app on macOS and Linux.

Splash screen

Build a custom splash screen that loads before your MainWindow.

Rect painter

Create a custom rendered control that interacts with the mouse to form a simple paint application.

Loading images

See how to load images via XAML, bindings and from the internet.

Using fonts

Use custom fonts, such as Google fonts, within your application.

Battle City

A sample 2D game in Avalonia created without writing any rendering code.

Custom controls

Rating control

Create a rating control for users to vote by clicking one of several stars.

Snowflake control

Create a custom control that overrides OnRender to use more advanced rendering instead.

Testing

Headless testing wtih XUnit

Test your app without a visible graphic user interface using Avalonia's headless platform with XUnit.

Headless testing with NUnit

Test your app without a visible graphic user interface using Avalonia's headless platform with NUnit.

Testing with Appium

Automated tests for UI interactions, such as button clicks, text input, and screen navigation.

Other

Clipboard operations

Interact with the device's clipboard to copy and paste text.

Drag-and-drop operations

Implement dragging and dropping in an Avalonia app.

Native file operations

Using native 'Save as' and 'Open file' dialogs.

IoC file operations

Using native 'Save as' and 'Open file' dialogs with inversion of control (IoC).

Localization

An example of how to localize an Avalonia app.

Basic view locator

Change the contents of your UI using a view locator.

Native AOT

Set up your app to build with native ahead-of-time (AOT).

Discussion

Have questions or feedback? Join the conversation below.