agentleFS
vchelaruvchelaru/Gum/.claude/skills/gum-tool-viewmodels/SKILL.md

gum-tool-viewmodels

Skill659 starsChanged 2 months agoMITView on GitHub

Gum tool ViewModel conventions. Triggers: ViewModels, XAML views, data binding, DependsOn, visibility properties.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 0 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Stored properties: use Get<T>()/Set():

    line 15
  2. Very specific:

    Derived properties: must use [DependsOn] so changes to the source property automatically raise PropertyChanged for the derived property.

    line 27
  3. Very specific:

    Do not use IValueConverter or DataTrigger for logic.

    line 49
  4. Very specific:

    Keep the *logical* state on the VM (IsOrphaned, IsInvalid, etc., still [DependsOn]-driven and unit-testable).

    line 72
  5. Very specific:

    Missing [DependsOn]: If a getter computes from another property but lacks the attribute, the UI will show stale values.

    line 81

≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Gum Tool ViewModel Conventions

Base Classes

  • ViewModel (Gum/Mvvm/ViewModel.cs) — base for all view models. Provides Get<T>()/Set() property storage, NotifyPropertyChanged, and [DependsOn] propagation.
  • DialogViewModel (Tools/Gum.Presentation/Dialogs/DialogViewModel.cs) — extends ViewModel for dialogs. Adds AffirmativeCommand/NegativeCommand, RequestClose event, and AffirmativeText/NegativeText. Lives in the headless Gum.Presentation assembly (ADR-0005). Any dialog VM deriving from it is safe to relocate there: DialogViewResolver falls back to scanning other loaded assemblies (IDialogViewAssemblyProvider) when the VM's own assembly has no View — but that fallback only pairs via [Dialog(typeof(VM))] on the View, not naming convention, so attribute the View before (or alongside) moving its VM. See gum-tool-dialogs.

Property Patterns

Stored properties use Get<T>()/Set():

public string Name
{
    get => Get<string>() ?? string.Empty;
    set => Set(value);
}

A backing field with Set(ref _field, value) is the faster alternative for hot properties (no dictionary lookup; a field initializer counts as already set, so assigning the initial value raises nothing). Tool view models keep Get<T>()/Set(value) by default.

Derived properties must use [DependsOn] so changes to the source property automatically raise PropertyChanged for the derived property. Without this, the UI will not update.

[DependsOn(nameof(SourceType))]
public bool IsLocalFile => SourceType == SourceType.LocalFile;

Multiple dependencies are expressed with multiple attributes:

[DependsOn(nameof(IsPreviewLoaded))]
[DependsOn(nameof(IsLoading))]
public bool CanImport => IsPreviewLoaded && !IsLoading;

View Logic on the VM, Not in XAML

The boundary is logic vs. theming:

  • Logic — what to show, when, in what state — lives on the VM as [DependsOn] computed properties, in framework-neutral types (ADR-0004). Examples: bool visibility flags, FontStyle, display strings, enabled/disabled flags. XAML binds directly (a bool visibility flag through a stock BooleanToVisibilityConverter). Unit-testable, and the VM stays eligible for the headless assembly.
  • Theming — which brush, which font size — stays in XAML so {DynamicResource ...} can repaint on a runtime theme switch. Not testable, by necessity (DynamicResource only resolves through a FrameworkElement).

Do not use IValueConverter or DataTrigger for logic. The one exception is themed brushes (see below).

Visibility example — expose a bool, not WPF Visibility (ADR-0004), so the VM can move into the headless assembly:

[DependsOn(nameof(ErrorMessage))]
public bool IsErrorMessageVisible => !string.IsNullOrEmpty(ErrorMessage);

XAML binds through the stock BooleanToVisibilityConverter (a pure type-adapter, not logic):

<TextBlock Visibility="{Binding IsErrorMessageVisible, Converter={StaticResource BoolToVisibilityConverter}}" />

Never expose System.Windows types from a VM — Visibility, Color, Brush, WriteableBitmap. They pin the VM to the WPF assembly and defeat the compiler-enforced logic↔view boundary. Resolve display state in neutral types instead: bool for visibility, Gum's color type (RenderingLibrary has one) for colors, a color in place of a Brush, byte[]/a Gum image for pixels. Framework types live only in the view/converter layer. See Direction/decisions/0004-viewmodels-expose-neutral-presentation-state.md.

VMs in GumCommon or runtime projects must stay UI-agnostic — this rule is for tool code only.

Exception: themed brushes

Light/dark theming uses brushes defined in Gum/Themes/Frb.Brushes.{Light,Dark}.xaml (e.g. Frb.Brushes.Error). These must be resolved with {DynamicResource ...} so a runtime theme switch repaints — that only works from a FrameworkElement, not from a VM-side Brush property. The right pattern:

  • Keep the logical state on the VM (IsOrphaned, IsInvalid, etc., still [DependsOn]-driven and unit-testable).
  • Apply the brush via a Style with a DataTrigger keyed off that VM bool, e.g. <Setter Property="Foreground" Value="{DynamicResource Frb.Brushes.Error}" />.

This is the only situation where DataTrigger is preferred over a VM-side property.

A clickable text link in the Avalonia head is a HyperlinkButton, never a transparent Button: the head's Button style forces white Primary.Contrast text, while HyperlinkButton takes Frb.Brushes.Link per theme through FrbThemeResources.ControlBrushAliases.

Common Pitfalls

Missing [DependsOn]: If a getter computes from another property but lacks the attribute, the UI will show stale values. The ViewModel constructor scans for [DependsOn] via reflection at construction time — it only works if the attribute is present.

Two-way derived properties: Properties like IsLocalFile that both read from and write to a backing property need [DependsOn] for the read direction. The write direction (setter updating SourceType) works normally through Set().

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.