avalonia-viewmodels-zafiro
使用 Zafiro 模式建構反應式 Avalonia UI 應用程式
建立可維護的 Avalonia 應用程式需要一致的 ViewModel 模式和導覽結構。此技能提供經過驗證的 ReactiveUI 和 Zafiro 工具包模式,用於穩健的 UI 開發。
下載技能 ZIP
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
開啟並開始使用
測試它
正在使用「avalonia-viewmodels-zafiro」。 產生具有使用者名稱和密碼欄位的登入畫面 ViewModel
預期結果:
一個繼承自 ReactiveObject 的 partial class LoginViewModel,具有用於 Username 和 Password 屬性的 [Reactive] 屬性,透過 ReactiveCommand.CreateFromTask 建立的 LoginCommand 包含驗證,以及使用 CompositeDisposable 進行清理的適當 IDisposable 實現。
正在使用「avalonia-viewmodels-zafiro」。 當使用者點擊項目時,如何從 HomeViewModel 導覽到 DetailsViewModel?
預期結果:
將 INavigator 注入 HomeViewModel 建構函式,然後在您的選擇處理常式中呼叫 await navigator.Navigate(() => new DetailsViewModel(selectedItem))。DataTypeViewLocator 會自動解析對應的 DetailsView。
安全審計
安全Static analyzer flagged 79 potential issues (71 external_commands, 8 blocker patterns). All findings are FALSE POSITIVES. The detected 'backtick execution' patterns are markdown code fence markers (```) and C# attribute syntax ([Section], [Reactive]). The 'blocker' patterns are documentation callouts ([!TIP], [!IMPORTANT]). This skill contains only documentation markdown files with C# code examples - no executable code or security risks exist.
品質評分
你能建構什麼
具有模組化區塊的桌面應用程式
使用 [Section] 屬性建構錢包應用程式,包含自動發現的區塊如 Wallet、Browse 和 Settings,並使用 INavigator 在視圖之間實現無縫導覽。
複雜多步驟工作流程實現
使用 WizardBuilder 建立專案設定精靈,包含驗證、進度追蹤和條件式導覽,使用 WhenValid 和 NextCommand 規則定義步驟。
反應式命令基礎設施設定
透過 HandleErrorsWith 建立穩健的命令模式與錯誤處理,使用 CompositeDisposable 進行自動處置管理,並使用 WhenAnyValue 進行反應式屬性觀察。
試試這些提示
建立一個用於使用者個人資料畫面的 ReactiveUI ViewModel,包含 Name、Email 和 IsBusy 屬性。加入一個 Save 命令,在執行前驗證電子郵件格式。使用 [Reactive] 屬性和適當的處置處理。
展示如何實作具有三個區塊的側邊欄導覽:Dashboard、Reports 和 Settings。使用帶有 FontAwesome 圖示的 [Section] 屬性,並展示如何使用 IShellViewModel 在區塊之間切換。
演示為資料同步建立 IEnhancedCommand,顯示進度、透過 NotificationService 處理錯誤,並正確處置訂閱。包含取消支援和基於連線狀態的反應式啟用/停用邏輯。
最佳實務
- 始終在訂閱和命令上使用 .DisposeWith(disposables) 以防止反應式串流中的記憶體洩漏
- 使用 [Section] 屬性標記區塊 ViewModel 以進行自動註冊,而不是在 CompositionRoot 中手動連接
- 使用 HandleErrorsWith 擴充功能將命令錯誤傳送到 NotificationService 以進行一致的使用者回饋
避免
- 不要在工廠方法之外手動使用 'new' 實例化 ViewModel - 透過 CompositionRoot 使用依賴注入
- 避免在沒有將可觀察物件加入 CompositeDisposable 的情況下訂閱 - 這會導致記憶體洩漏
- 永遠不要在命令執行中封鎖非同步操作 - 始終使用 CreateFromTask 並 await 導覽呼叫
常見問題
使用這些模式需要什麼依賴項?
自動區塊發現如何運作?
我可以在沒有完整 Zafiro 工具包的情況下使用這些模式嗎?
如何在精靈步驟中處理驗證?
IEnhancedCommand 相對於標準 ICommand 的目的是什麼?
如何測試使用這些模式建立的 ViewModel?
開發者詳情
作者
sickn33授權
MIT
儲存庫
https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/avalonia-viewmodels-zafiro引用
main
檔案結構