Welcome to the Avalonia Boilerplate repository! This project serves as a starter template for building mobile applications using Avalonia. It is designed to help beginners set up a mobile application environment with ease, providing essential features and a clean architecture based on the MVVM pattern with Prism.Avalonia. This boilerplate includes navigation, font icons, SVG support, and a toast notification service.
- MVVM Pattern with Prism.Avalonia: Clean separation of concerns with the MVVM architecture.
- Navigation: Easy and intuitive navigation system.
- Font Icons: Support for font icons to enhance the UI.
- SVG Support: Integration for SVG images.
- Toast Service: Built-in service for displaying toast notifications.
Follow these steps to get your project up and running.
-
Clone the repository:
git clone git@github.com:exendahal/avalonia_new.git cd avalonia_new
-
Restore dependencies:
dotnet restore
-
Build the project:
dotnet build
-
Run the application:
dotnet run
- /avalonia_new: Contains the main application code.
- /Views: XAML files for UI components.
- /ViewModels: C# files for view models.
- /Models: Data models.
- /Services: Implementation of services (e.g., toast notifications).
- /Resources: Contains fonts, SVGs, and other resources.
This boilerplate follows the MVVM pattern using Prism.Avalonia. Here's a brief overview:
Create your ViewModels in the /ViewModels
directory. Here's an example of a simple ViewModel:
public class MainViewModel : BindableBase
{
private string _title = "Hello, Avalonia!";
public string Title
{
get => _title;
set => SetProperty(ref _title, value);
}
}
Create your Views in the /Views
directory and bind them to ViewModels. Here's an example of a simple View:
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<TextBlock Text="{Binding Title}" />
</UserControl>
Use Prism's navigation service to handle navigation between views.
Add your font icons and SVG images to the /Resources
directory and reference them in your views.
To use the toast service, call the ShowToast method with a message and toast type. Available toast types are Success, Warning, and Failed:
ToastHelper.ShowToast("Welcome", Services.ToastService.ToastType.Success);
Thank you for using the Avalonia Mobile Boilerplate! If you have any questions or feedback, feel free to open an issue or submit a pull request. Happy coding!