| name | designing-avalonia-customcontrol-architecture |
| description | Defines the basic solution structure for AvaloniaUI Desktop Applications using CustomControl. Use when creating new AvaloniaUI projects or designing stand-alone control styles with ControlTheme. |
6.5 Writing AXAML Code
- When generating AXAML code, use CustomControl with ControlTheme for Stand-Alone Control Style
- Purpose: Theme separation and minimizing style dependencies
6.5.1 AvaloniaUI Custom Control Library Project Structure
Recommended Project Structure:
YourAvaloniaSolution
โโโ YourCustomControlProject1/
โ โโโ Properties/
โ โ โโโ AssemblyInfo.cs โ AssemblyInfo.cs definition
โ โโโ Themes/
โ โ โโโ Generic.axaml โ ControlTheme definition
โ โ โโโ CustomButton1.axaml โ Individual control theme
โ โ โโโ CustomTextBox1.axaml โ Individual control theme
โ โโโ CustomButton1.cs
โ โโโ CustomTextBox1.cs
โโโ YourCustomControlProject2/
โโโ Properties/
โ โโโ AssemblyInfo.cs โ AssemblyInfo.cs definition
โโโ Themes/
โ โโโ Generic.axaml โ ControlTheme definition
โ โโโ CustomButton2.axaml โ Individual control theme
โ โโโ CustomTextBox2.axaml โ Individual control theme
โโโ CustomButton2.cs
โโโ CustomTextBox2.cs
6.6 โ ๏ธ Distinguishing ResourceInclude vs MergeResourceInclude
- ResourceInclude: Used in regular ResourceDictionary files (Generic.axaml, Styles, etc.)
- MergeResourceInclude: Used only in Application.Resources (App.axaml)
Advantages:
- Complete separation of theme and logic based on ControlTheme
- Flexible style variations through CSS Classes
- State management via Pseudo Classes (:pointerover, :pressed, etc.)
- Theme modularization through ResourceInclude
- Work can be split by file for team collaboration
6.5.2 Key Differences Between WPF and AvaloniaUI
| Item | WPF | AvaloniaUI |
|---|
| File Extension | .xaml | .axaml |
| Style Definition | Style + ControlTemplate | ControlTheme |
| State Management | Trigger, DataTrigger | Pseudo Classes, Style Selector |
| CSS Support | โ | โ
(Classes attribute) |
| Resource Merging | MergedDictionaries + ResourceDictionary | MergedDictionaries + ResourceInclude |
| Dependency Props | DependencyProperty | StyledProperty, DirectProperty |