Avalonia App Builder
Workflow
- •Confirm project conventions before coding.
- •Implement UI in Avalonia XAML (not control construction in code-behind).
- •Implement view-model state with CommunityToolkit.Mvvm partial observable properties.
- •Wire views/view-models using ViewLocator naming conventions.
- •Apply binding and theming rules.
- •Validate class/member ordering and compiled-binding coverage.
Core Conventions
UI and XAML
- •Use Avalonia-specific XAML for layout and visuals.
- •Avoid creating controls in code-behind unless explicitly required by the user.
- •Define styles/resources in dedicated dictionaries and merge them in
App.axaml. - •Use
StaticResourcefor immutable values andDynamicResourceonly when runtime updates are needed. - •For light/dark resources, use:
xaml
<ResourceDictionary.ThemeDictionaries> <!-- theme dictionaries --> </ResourceDictionary.ThemeDictionaries>
MVVM and Properties
- •Use
CommunityToolkit.Mvvmversion>= 8.4.0patterns. - •Define observable properties as partial properties:
csharp
[ObservableProperty]
public partial string Title { get; set; } = string.Empty;
- •Prefer one-way bindings unless user input must update the view-model.
Binding Rules
- •Use compiled bindings only. Set explicit
x:DataTypeon all binding scopes:- •Views
- •DataTemplates
- •Control themes
- •Resource dictionaries where bindings are used
- •Do not write logical expressions in bindings (for example,
&&or combined conditions). - •Boolean inversion with
!is allowed for a single bound boolean:- •Valid:
{Binding !IsConnecting} - •Invalid:
{Binding !IsConnecting && !IsUpdating}
- •Valid:
ViewLocator Conventions
- •Respect ViewLocator naming:
- •
MyViewModelresolves toMyView.axaml
- •
- •Keep view-model and view names aligned to avoid runtime lookup failures.
Custom Controls
- •Use
StyledPropertyonly when the value must participate in styling. - •Prefer
DirectPropertyfor non-styled properties. - •Prefer custom controls or control re-templating for strong UX, instead of CRUD-like default layouts.
C# Member Ordering
Order members by access level and member type. Use this structure:
- •
publicmembers - •
internalmembers - •
protectedmembers - •
privatemembers
Within each access level, order by:
- •fields
- •constructors
- •properties
- •commands
- •events
- •methods
Delivery Checklist
Before finishing, verify:
- •All new/changed UI is written in Avalonia XAML.
- •All bindings are compiled and have correct
x:DataTypescopes. - •No invalid logical binding expressions were introduced.
- •View/view-model names follow ViewLocator convention.
- •Theme resources use
ResourceDictionary.ThemeDictionarieswhere needed. - •View-model observable properties use toolkit partial-property style.
- •Member ordering follows the required class layout.
Reference
- •Avalonia repository: https://github.com/AvaloniaUI/Avalonia