designing-avalonia-customcontrol-architecture
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 |
More from christian289/dotnet-with-claudecode
converting-html-css-to-wpf-xaml
Converts HTML/CSS to WPF CustomControl XAML with correct patterns and common pitfall solutions. Use when transforming web designs to WPF, converting CSS animations to Storyboards, implementing CSS border-radius clipping, CSS pseudo-elements (::before/::after), or CSS transforms in XAML.
56publishing-wpf-apps
Guides WPF application publishing and installer options. Use when user mentions publish, deploy, release, packaging, or installer to help choose deployment method and installer technology.
14using-avalonia-collectionview
Provides CollectionView alternatives for AvaloniaUI using DataGridCollectionView and ReactiveUI. Use when filtering, sorting, or grouping collections in AvaloniaUI applications.
9using-xaml-property-element-syntax
Converts long inline XAML bindings to Property Element Syntax for better readability. Use when XAML binding expressions become too long or complex.
8managing-styles-resourcedictionary
Manages WPF Style definitions and ResourceDictionary patterns including BasedOn inheritance and resource merging. Use when building theme systems, organizing resources, or choosing between StaticResource and DynamicResource.
8configuring-avalonia-dependency-injection
Configures GenericHost and Dependency Injection in AvaloniaUI applications. Use when setting up DI container, registering services, or implementing IoC patterns in AvaloniaUI projects.
7