/desktop-avalonia:avalonia-mvvmfrom desktop-avalonia
Avalonia + CommunityToolkit.Mvvm 桌面專案的 MVVM 慣例——ViewModel 結構、ObservableProperty/RelayCommand、compiled bindings、設計時支援與 AXAML 特殊情境。Use when 撰寫或修改 Avalonia View/ViewModel、寫 AXAML binding、處理對話框回傳、DataGrid 命令綁定、avalonia mvvm、observableproperty、relaycommand。
Ships in desktop-avalonia. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
以 CommunityToolkit.Mvvm 實作 MVVM。以下慣例適用任何 Avalonia + CommunityToolkit.Mvvm 桌面專案。
partial class,繼承共用基底(如 ObservableObject 或專案自訂的 ViewModelBase)。[ObservableProperty] 特性標註私有欄位(_camelCase),由 source generator 產生對應的公開屬性。[RelayCommand] 特性;需啟用/停用時以 CanExecute 連結布林屬性。partial void OnXxxChanged(T value),不要在屬性 setter 內手寫邏輯。public partial class ExampleViewModel : ObservableObject
{
[ObservableProperty]
private string _keyword = string.Empty;
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(SearchCommand))]
private bool _canSearch;
[RelayCommand(CanExecute = nameof(CanSearch))]
private async Task SearchAsync()
{
// ...
}
partial void OnKeywordChanged(string value)
{
CanSearch = !string.IsNullOrWhiteSpace(value);
}
}
每個 ViewModel 同時提供兩種建構函式:
View 的 DataContext 一律透過 DI 注入取得 ViewModel 實例,不在 AXAML 中硬編碼具體型別。
x:DataType="vm:XxxViewModel",享有編譯期型別檢查與較佳效能。MultiBinding + BoolConverters.And 等在 XAML 層堆疊邏輯,改用 ViewModel 上的計算屬性(computed property)承載,讓判斷邏輯可測試。DataGrid 內按鈕綁定命令:DataGrid 的資料列 DataContext 是列項目而非外層 ViewModel,需以具名元素回指外層 ViewModel:
Command="{Binding #DataGridName.((vm:ExampleViewModel)DataContext).RemoveCommand}"
資料列著色:在 code-behind 處理 DataGrid 的 LoadingRow 事件,依列資料狀態套用樣式,不在 XAML 內用複雜 converter 硬湊。
Avalonia 資源(icon、圖片等)必須在 .csproj 以 <AvaloniaResource> 宣告,才會嵌入發佈包;否則發佈後執行時找不到資源:
<ItemGroup>
<AvaloniaResource Include="Assets/**" />
</ItemGroup>
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub kerryhuang/kerryhuang-plugins --plugin desktop-avalonia3 skills in this plugin
/cross-platformAvalonia 桌面專案的跨平台慣例——Windows/macOS/Linux 相容的路徑處理、平台判斷、腳本語法與 null 裝置寫法。Use when 寫檔案路徑、判斷作業系統、寫 shell 腳本或 CI workflow、避免 Windows 專用指令、cross platform、path.combine、跨平台腳本。/desktop-build-publishAvalonia 桌面應用的建置與發佈——dotnet build 驗證、跨平台單一執行檔發佈(win/osx/linux RID)、macOS .app/.dmg 打包與輸出位置。Use when 使用者說「建置」「build」「編譯」「發佈」「publish」「打包」「產生執行檔」「single file」「self-contained」或要建立 Windows/macOS/Linux 可執行檔。