Pular para o conteúdo
Skillpedia
APIs e servidores (backend)40 mil · #5247

mvvm-toolkit

Ajuda seu agente a criar aplicativos .NET com padrões MVVM. Ele gera código para propriedades, comandos e validação.

O que ela faz

Esta ferramenta ajuda programadores a escreverem código para aplicativos de forma mais eficiente. Ela automatiza partes repetitivas da criação de interfaces de usuário e comandos, tornando o desenvolvimento mais rápido e menos propenso a erros.

Quando usar

  • ✓Ao criar ou revisar a lógica de exibição (ViewModel) em um aplicativo.
  • ✓Quando você precisa definir botões ou ações que o usuário pode executar.
  • ✓Ao validar as informações que o usuário insere em formulários.

Exemplo do que pedir para a IA

“Como posso fazer um botão que salva os dados do usuário e só funciona se o campo de nome não estiver vazio?”

Quer saber mais? Abra as seções abaixo.

Como usar

O jeito mais fácil: copie a mensagem abaixo e cole no Claude, ChatGPT, Cursor ou outra IA. Ela lê a skill e segue as instruções.

Link da skill

https://github.com/github/awesome-copilot/blob/main/skills/mvvm-toolkit/SKILL.md

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/github/awesome-copilot/blob/main/skills/mvvm-toolkit/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Como funciona

A ferramenta usa 'geradores de código' que criam automaticamente código extra com base em anotações simples que o programador adiciona. Isso evita que o programador escreva muito código repetitivo manualmente.

Instalação

Jeito mais fácil: copie o link da skill e cole no Claude, ChatGPT ou Cursor pedindo para seguir as instruções.

No terminal (Claude Code, Codex, Cursor), na pasta do projeto:

npx skills add github/awesome-copilot --skill mvvm-toolkit

Ou baixe só o arquivo:

curl -L https://raw.githubusercontent.com/github/awesome-copilot/main/skills/mvvm-toolkit/SKILL.md -o SKILL.md
Conteúdo técnico (SKILL.md)

Tradução do texto original do autor no GitHub. Os comandos e códigos estão como no original.

CommunityToolkit.Mvvm (core)

Use this skill when authoring or reviewing ViewModels, properties, commands, or validation in apps that use CommunityToolkit.Mvvm 8.x.

Companion skills. Load mvvm-toolkit-messenger for IMessenger pub/sub patterns. Load mvvm-toolkit-di for Microsoft.Extensions.DependencyInjection integration.

Quick recap. [ObservableProperty] on private fields in partial classes; [RelayCommand] on instance methods; inherit from ObservableObject (or ObservableValidator for input forms, ObservableRecipient when using IMessenger).


Package & setup

<ItemGroup>
  <PackageReference Include="CommunityToolkit.Mvvm" Version="8.*" />
</ItemGroup>

Targets: netstandard2.0, netstandard2.1, net6.0+. Works on .NET, .NET Framework, Mono. Source generators ship in the same NuGet — no extra analyzer reference required.

Namespaces:

using CommunityToolkit.Mvvm.ComponentModel;   // ObservableObject, [ObservableProperty]
using CommunityToolkit.Mvvm.Input;             // [RelayCommand], RelayCommand, AsyncRelayCommand

Universal rule. Every type that uses [ObservableProperty] or [RelayCommand] — and every enclosing type, if nested — must be declared partial. Without it, the generators emit MVVMTK0008 / MVVMTK0042.


Source generators cheat sheet

Attribute Applied to Generates
[ObservableProperty] private field Public INotifyPropertyChanged property + OnXxxChanging/OnXxxChanged partial-method hooks
[NotifyPropertyChangedFor(nameof(Other))] observable field Also raises PropertyChanged for the listed property
[NotifyCanExecuteChangedFor(nameof(MyCommand))] observable field Calls MyCommand.NotifyCanExecuteChanged() on change
[NotifyDataErrorInfo] observable field on ObservableValidator Calls ValidateProperty(value) from the setter
[NotifyPropertyChangedRecipients] observable field on ObservableRecipient Broadcast(old, new) after the change
[RelayCommand] instance method Lazy RelayCommand / AsyncRelayCommand exposed as IRelayCommand / IAsyncRelayCommand
[RelayCommand(CanExecute = nameof(CanX))] instance method Wires CanExecute to a method or property
[RelayCommand(IncludeCancelCommand = true)] async method with CancellationToken Also generates XxxCancelCommand
[RelayCommand(AllowConcurrentExecutions = true)] async method Allows queued/parallel invocations (default disables while running)
[RelayCommand(FlowExceptionsToTaskScheduler = true)] async method Surfaces exceptions via ExecutionTask instead of awaiting and rethrowing
[property: SomeAttr] observable field or [RelayCommand] method Forwards SomeAttr onto the generated property (e.g., [JsonIgnore])

Naming. Field name / _name / m_name → Name. Method LoadAsync → LoadCommand (the Async suffix is stripped; a leading On is also stripped).

See references/source-generators.md for the full attribute reference with generated-code samples.


ViewModel patterns

Simple observable property

public partial class ContactViewModel : ObservableObject
{
    [ObservableProperty]
    private string? name;
}

Hooks: OnXxxChanging / OnXxxChanged

[ObservableProperty]
private string? name;

partial void OnNameChanged(string? value) =>
    Logger.LogInformation("Name changed to {Name}", value);

Both single-arg (value) and two-arg (oldValue, newValue) overloads are available. Implement only the ones you need; unimplemented hooks are elided by the compiler (zero runtime cost).

Dependent properties + dependent commands

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(FullName))]
[NotifyCanExecuteChangedFor(nameof(SaveCommand))]
private string? firstName;

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(FullName))]
[NotifyCanExecuteChangedFor(nameof(SaveCommand))]
private string? lastName;

public string FullName => $"{FirstName} {LastName}".Trim();

Wrapping a non-observable model

public sealed class ObservableUser(User user) : ObservableObject
{
    public string Name
    {
        get => user.Name;
        set => SetProperty(user.Name, value, user, (u, n) => u.Name = n);
    }
}

…

Perguntas frequentes

Preciso instalar algo extra?

Não, a ferramenta principal já vem junto com a instalação do pacote `CommunityToolkit.Mvvm`.

O que são 'geradores de código'?

São ferramentas que escrevem código automaticamente para você, com base em instruções que você fornece. Elas ajudam a evitar a escrita de código repetitivo.

Quando devo usar `ObservableValidator` em vez de `ObservableObject`?

Use `ObservableValidator` quando seu aplicativo precisa validar as informações que o usuário digita em formulários, como verificar se um campo obrigatório foi preenchido.

Detalhes

Descrição original do autor

CommunityToolkit.Mvvm (the MVVM Toolkit) core: source generators ([ObservableProperty], [RelayCommand], [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [NotifyDataErrorInfo]), base classes (ObservableObject / ObservableValidator / ObservableRecipient), commands (RelayCommand / AsyncRelayCommand), and validation. Companion skills: mvvm-toolkit-messenger for pub/sub, mvvm-toolkit-di for Mi

repo: github/awesome-copilot

Popularidade

Estrelas no GitHub
40 mil
Posição no ranking
#5247
Licença
MIT
Atualizada em
15/10/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas