mvvm-toolkit
Skill này làm gì
Công cụ này giúp lập trình viên viết mã cho ứng dụng hiệu quả hơn. Nó tự động hóa những phần lặp đi lặp lại khi tạo giao diện người dùng và lệnh, giúp phát triển nhanh hơn và ít lỗi hơn.
Khi nào nên dùng
- ✓Khi bạn tạo hoặc rà soát logic hiển thị (ViewModel) trong ứng dụng.
- ✓Khi bạn cần định nghĩa các nút hoặc hành động mà người dùng có thể thực hiện.
- ✓Khi bạn kiểm tra thông tin người dùng nhập vào biểu mẫu.
Liên kết skill
https://github.com/github/awesome-copilot/blob/main/skills/mvvm-toolkit/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Làm thế nào để tạo một nút lưu dữ liệu người dùng và chỉ hoạt động khi ô tên không để trống?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Công cụ dùng các 'code generators' tự động tạo thêm mã dựa trên các chú thích đơn giản mà lập trình viên thêm vào. Điều này giúp lập trình viên không phải viết tay quá nhiều mã lặp lại.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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-messengerforIMessengerpub/sub patterns. Loadmvvm-toolkit-diforMicrosoft.Extensions.DependencyInjectionintegration.
Quick recap.
[ObservableProperty]on private fields inpartialclasses;[RelayCommand]on instance methods; inherit fromObservableObject(orObservableValidatorfor input forms,ObservableRecipientwhen usingIMessenger).
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 declaredpartial. Without it, the generators emitMVVMTK0008/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);
}
}
…
Câu hỏi thường gặp
Tôi có cần cài thêm gì không?
Không, công cụ chính đi kèm khi bạn cài gói `CommunityToolkit.Mvvm`.
“Code generators” là gì?
Đó là các công cụ tự động viết mã cho bạn dựa trên hướng dẫn bạn cung cấp. Chúng giúp tránh viết mã lặp lại.
Khi nào nên dùng `ObservableValidator` thay vì `ObservableObject`?
Dùng `ObservableValidator` khi ứng dụng cần kiểm tra thông tin người dùng nhập vào biểu mẫu, chẳng hạn như kiểm tra một trường bắt buộc đã được điền chưa.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 40k
- Vị trí xếp hạng
- #7304
- Giấy phép
- MIT
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
acquire-codebase-knowledge
40kGiúp agent của bạn hiểu và ghi tài liệu cho một dự án mã nguồn có sẵn. Hữu ích khi đón thành viên mới hoặc nắm tổng quan về kiến trúc.
acreadiness-assess
40kGiúp agent của bạn đánh giá mức độ sẵn sàng cho AI của dự án và tạo báo cáo. Hữu ích để biết dự án đã sẵn sàng dùng công cụ AI đến đâu.
acreadiness-generate-instructions
40kGiúp agent của bạn tạo hướng dẫn cho công cụ AI dựa trên kết quả đánh giá. Hữu ích để cải thiện cách AI làm việc với mã và khắc phục các khoảng trống.
acreadiness-policy
40kGiúp agent của bạn xác định hoặc áp dụng chính sách đánh giá dự án bằng AI. Hữu ích để chuẩn hóa cách đánh giá dự án và đảm bảo tuân thủ.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.