What You’ll Build
A fully functional Todo application with:- Add, complete, and delete tasks
- Filter tasks by status (All, Active, Completed)
- Persistent data using ViewModel
- Clean MVVM architecture
- Modern Fluent UI design
This tutorial builds on concepts from the Quick Start guide. Make sure you’re comfortable with basic Avalonia concepts before proceeding.
Project Setup
Add Required Packages
The MVVM template includes CommunityToolkit.Mvvm, but let’s ensure we have everything:
Creating the Todo Model
First, let’s create a model to represent a todo item.Building the ViewModel
Now let’s create a ViewModel to manage our todo list logic.Designing the User Interface
Now let’s create a beautiful, functional UI.Running Your Application
Key Concepts Explained
ObservableCollection
ObservableCollection automatically notifies the UI when items are added or removed, keeping the list synchronized.
RelayCommand with Parameters
CommandParameter:
Computed Properties
Key Bindings
Parent Binding
$parent[Window] navigates up the visual tree to access the window’s DataContext.
Enhancing Your Application
Adding Persistence
To save todos between sessions, add JSON serialization:Adding Animations
Add smooth transitions for completed items:Custom Themes
Create custom color schemes by modifying the App.axaml:App.axaml
Best Practices
Separation of Concerns
Keep your Models, ViewModels, and Views separate. Models contain data, ViewModels contain logic, and Views contain UI.
Use Commands
Always use commands instead of event handlers in XAML for better testability and MVVM compliance.
Observable Properties
Use
[ObservableProperty] for automatic change notification rather than manually implementing INotifyPropertyChanged.Data Binding
Leverage data binding to keep UI in sync with data automatically, avoiding manual UI updates.
What You’ve Learned
Congratulations! You’ve built a complete Avalonia application and learned:- ✅ Application structure and MVVM pattern
- ✅ Data binding with ObservableCollection
- ✅ Commands with and without parameters
- ✅ Layout controls (DockPanel, Grid, StackPanel)
- ✅ Styling and theming
- ✅ User input handling
- ✅ Collection filtering and computed properties
- ✅ Complex UI layouts with templates
Next Steps
Data Binding
Learn advanced binding techniques and converters
Styling & Themes
Master Avalonia’s powerful styling system
Custom Controls
Build reusable custom controls
Dialogs & Navigation
Implement multi-window apps and dialogs