技能 编程开发 Avalonia 界面布局最佳实践

Avalonia 界面布局最佳实践

v20261106
avalonia-layout-zafiro
本技能提供使用 Zafiro.Avalonia 创建现代且可维护的 Avalonia UI 布局指南。强调语义容器、共享样式和最小化 XAML 冗余。用户将学习避免硬编码颜色或深层嵌套等反模式,转而利用行为和通用组件编写更清晰的代码。
获取技能
483 次下载
概览

Avalonia Layout with Zafiro.Avalonia

Master modern, clean, and maintainable Avalonia UI layouts.
Focus on semantic containers, shared styles, and minimal XAML.

🎯 Selective Reading Rule

Read ONLY files relevant to the layout challenge!


📑 Content Map

FileDescriptionWhen to Read
themes.mdTheme organization and shared stylesSetting up or refining app themes
containers.mdSemantic containers (HeaderedContainer, EdgePanel, Card)Structuring views and layouts
icons.mdIcon usage with IconExtension and IconOptionsAdding and customizing icons
behaviors.mdXaml.Interaction.Behaviors and avoiding ConvertersImplementing complex interactions
components.mdGeneric components and avoiding nestingCreating reusable UI elements

🔗 Related Project (Exemplary Implementation)

For a real-world example, refer to the Angor project:
/mnt/fast/Repos/angor/src/Angor/Avalonia/Angor.Avalonia.sln


✅ Checklist for Clean Layouts

  • [ ] Used semantic containers? (e.g., HeaderedContainer instead of Border with manual header)
  • [ ] Avoided redundant properties? Use shared styles in axaml files.
  • [ ] Minimized nesting? Flatten layouts using EdgePanel or generic components.
  • [ ] Icons via extension? Use {Icon fa-name} and IconOptions for styling.
  • [ ] Behaviors over code-behind? Use Interaction.Behaviors for UI-logic.
  • [ ] Avoided Converters? Prefer ViewModel properties or Behaviors unless necessary.

❌ Anti-Patterns

DON'T:

  • Use hardcoded colors or sizes (literals) in views.
  • Create deep nesting of Grid and StackPanel.
  • Repeat visual properties across multiple elements (use Styles).
  • Use IValueConverter for simple logic that belongs in the ViewModel.

DO:

  • Use DynamicResource for colors and brushes.
  • Extract repeated layouts into generic components.
  • Leverage Zafiro.Avalonia specific panels like EdgePanel for common UI patterns.
信息
分类 编程开发
名称 avalonia-layout-zafiro
版本 v20261106
大小 5.87KB
更新时间 2026-11-07
语言