
Avalonia Viewmodels Zafiro
Wire Avalonia desktop UI to Zafiro ViewModels with DataTypeViewLocator, DI composition root, and scoped ViewModel registration.
Overview
Avalonia-viewmodels-zafiro is an agent skill for the Build phase that maps Zafiro ViewModels to Avalonia Views via DataTypeViewLocator and a DI composition root.
Install
npx skills add https://github.com/sickn33/antigravity-awesome-skills --skill avalonia-viewmodels-zafiroWhat is this skill?
- Registers DataTypeViewLocator in App.axaml for automatic ViewModel-to-View mapping by data type
- Includes Zafiro.Avalonia DataTemplateInclude for shared framework templates
- Defines a CompositionRoot that builds ServiceCollection, AddViewModels, AddUIServices, and resolves IShellViewModel
- Shows ViewModel DI registration with Transient, Scoped, or Singleton lifetimes
- Documents naming conventions and source-generator registration patterns used in Zafiro projects
Adoption & trust: 475 installs on skills.sh; 40.1k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your Avalonia app grows messy because Views and ViewModels are manually coupled with no consistent locator or injection setup.
Who is it for?
Solo .NET devs starting or refactoring an Avalonia + Zafiro desktop app who need MVVM composition conventions.
Skip if: Web Blazor frontends, mobile Xamarin-only stacks, or teams not using Zafiro/Avalonia MVVM patterns.
When should I use this skill?
Building or refactoring Avalonia UI with Zafiro and need ViewModel-View mapping plus DI composition root patterns.
What do I get? / Deliverables
You have App.axaml locator registration, a CompositionRoot bootstrap, and scoped ViewModel services that resolve IShellViewModel cleanly.
- App.axaml DataTypeViewLocator and template includes
- CompositionRoot with registered ViewModels and resolved IShellViewModel
Recommended Skills
Journey fit
Build → Frontend is the canonical shelf for Avalonia view composition and MVVM mapping patterns in a shipping desktop client. Frontend covers view locators, data templates, and shell ViewModels—not backend APIs or deployment infra.
How it compares
Architecture skill for Zafiro on Avalonia—not a general WPF Prism or raw code-behind UI tutorial.
Common Questions / FAQ
Who is avalonia-viewmodels-zafiro for?
Indie and solo C# developers building Avalonia desktop apps with the Zafiro toolkit who want locator-based MVVM and DI.
When should I use avalonia-viewmodels-zafiro?
During Build frontend work when setting up App.axaml templates, shell composition, or registering new feature ViewModels.
Is avalonia-viewmodels-zafiro safe to install?
It provides C# and XAML patterns only; review the Security Audits panel on this Prism page before installing skills from third-party repos.
SKILL.md
READMESKILL.md - Avalonia Viewmodels Zafiro
# Composition & Mapping Ensuring your ViewModels are correctly instantiated and mapped to their corresponding Views is crucial for a maintainable application. ## ViewModel-to-View Mapping Zafiro uses the `DataTypeViewLocator` to automatically map ViewModels to Views based on their data type. ### Integration in App.axaml Register the `DataTypeViewLocator` in your application's data templates: ```xml <Application.DataTemplates> <DataTypeViewLocator /> <DataTemplateInclude Source="avares://Zafiro.Avalonia/DataTemplates.axaml" /> </Application.DataTemplates> ``` ### Registration Mappings can be registered globally or locally. Common practice in Zafiro projects is to use naming conventions or explicit registrations made by source generators. ## Composition Root Use a central `CompositionRoot` to manage dependency injection and service registration. ```csharp public static class CompositionRoot { public static IShellViewModel CreateMainViewModel(Control topLevelView) { var services = new ServiceCollection(); services .AddViewModels() .AddUIServices(topLevelView); var serviceProvider = services.BuildServiceProvider(); return serviceProvider.GetRequiredService<IShellViewModel>(); } } ``` ### Registering ViewModels Register ViewModels with appropriate scopes (Transient, Scoped, or Singleton). ```csharp public static IServiceCollection AddViewModels(this IServiceCollection services) { return services .AddTransient<IHomeSectionViewModel, HomeSectionSectionViewModel>() .AddSingleton<IShellViewModel, ShellViewModel>(); } ``` ## View Injection Use the `Connect` helper (if available) or manual instantiation in `OnFrameworkInitializationCompleted`: ```csharp public override void OnFrameworkInitializationCompleted() { this.Connect( () => new ShellView(), view => CompositionRoot.CreateMainViewModel(view), () => new MainWindow()); base.OnFrameworkInitializationCompleted(); } ``` > [!TIP] > Use `ActivatorUtilities.CreateInstance` when you need to manually instantiate a class while still resolving its dependencies from the `IServiceProvider`. # Navigation & Sections Zafiro provides powerful abstractions for managing application-wide navigation and modular UI sections. ## Navigation with INavigator The `INavigator` interface is used to switch between different views or viewmodels. ```csharp public class MyViewModel(INavigator navigator) { public async Task GoToDetails() { await navigator.Navigate(() => new DetailsViewModel()); } } ``` ## UI Sections Sections are modular parts of the UI (like tabs or sidebar items) that can be automatically registered. ### The [Section] Attribute ViewModels intended to be sections should be marked with the `[Section]` attribute. ```csharp [Section("Wallet", icon: "fa-wallet")] public class WalletSectionViewModel : IWalletSectionViewModel { // ... } ``` ### Automatic Registration In the `CompositionRoot`, sections can be automatically registered: ```csharp services.AddAnnotatedSections(logger); services.AddSectionsFromAttributes(logger); ``` ### Switching Sections You can switch the current active section via the `IShellViewModel`: ```csharp shellViewModel.SetSection("Browse"); ``` > [!IMPORTANT] > The `icon` parameter in the `[Section]` attribute supports FontAwesome icons (e.g., `fa-home`) when configured with `ProjektankerIconControlProvider`. --- name: avalonia-viewmodels-zafiro description: "Optimal ViewModel and Wizard creation patterns for Avalonia using Zafiro and ReactiveUI." risk: none source: community date_added: "2026-02-27" --- # Avalonia ViewModels with Zafiro This skill provides a set of best practices and patterns for creating ViewModels, Wizards, and managing navigation in Avalonia applications, leveraging the power of **ReactiveUI** and the **Zafiro** toolkit. ## Core Principles 1. **