davila7/claude-code-templates / cli-tool/components/skills/development/avalonia-viewmodels-zafiro
avalonia-viewmodels-zafiro
VerifiedOptimal ViewModel and Wizard creation patterns for Avalonia using Zafiro and ReactiveUI.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 1.6 KB |
| composition.md | markdown | 2.2 KB |
| navigation_sections.md | markdown | 1.3 KB |
| viewmodels.md | markdown | 1.7 KB |
| wizards.md | markdown | 1.5 KB |
viewmodels.md
View on GitHub# ViewModels & Commands
In a Zafiro-based application, ViewModels should be functional, reactive, and resilient.
## Reactive ViewModels
Use `ReactiveObject` as the base class. Properties should be defined using the `[Reactive]` attribute (from ReactiveUI.SourceGenerators) for brevity.
```csharp
public partial class MyViewModel : ReactiveObject
{
[Reactive] private string name;
[Reactive] private bool isBusy;
}
```
### Observation and Transformation
Use `WhenAnyValue` to react to property changes:
```csharp
this.WhenAnyValue(x => x.Name)
.Select(name => !string.IsNullOrEmpty(name))
.ToPropertyEx(this, x => x.CanSubmit);
```
## Enhanced Commands
Zafiro uses `IEnhancedCommand`, which extends `ICommand` and `IReactiveCommand` with additional metadata like `Name` and `Text`.
### Creating a Command
Use `ReactiveCommand.Create` or `ReactiveCommand.CreateFromTask` and then `Enhance()` it.
```csharp
public IEnhancedCommand Submit { get; }
public MyViewModel()
{
Submit = ReactiveCommand.CreateFromTask(OnSubmit, canSubmit)
.Enhance(text: "Submit Data", name: "SubmitCommand");
}
```
### Error Handling
Use `HandleErrorsWith` to automatically channel command errors to the `NotificationService`.
```csharp
Submit.HandleErrorsWith(uiServices.NotificationService, "Submission Failed")
.DisposeWith(disposable);
```
## Disposables
Always use a `CompositeDisposable` to manage subscriptions and command lifetimes.
```csharp
public class MyViewModel : ReactiveObject, IDisposable
{
private readonly CompositeDisposable disposables = new();
public void Dispose() => disposables.Dispose();
}
```
> [!TIP]
> Use `.DisposeWith(disposables)` on any observable subscription or command to ensure proper cleanup.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |