avalonia-data-templates

Define and apply Avalonia DataTemplates for view models with compiled bindings.

27|2|Updated Apr 23, 2026
One-click install
npx skills add https://github.com/linuxdevel/Avalonia-skills --skill avalonia-data-templates
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: avalonia-data-templates
Source: https://github.com/linuxdevel/Avalonia-skills/tree/main/skills/avalonia/avalonia-data-templates
Command: npx skills add https://github.com/linuxdevel/Avalonia-skills --skill avalonia-data-templates

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

DataTemplates, ContentTemplates, and template strategies are essential for clean UI composition in Avalonia. This skill consolidates how to define DataTemplates, ItemTemplates, ContentTemplates, TreeDataTemplates, and template selectors, and how compiled bindings with x:DataType influence performance and type safety.

Core Features & Use Cases

  • DataTemplate, ItemTemplate, and ContentTemplate usage across controls (ListBox, TreeView, DataGrid, ContentControl) with runtime-type matching.
  • App-level templates and template scope resolution for consistent UI across the app.
  • TreeDataTemplate for hierarchical data, and DataTemplate selectors (IDataTemplate) and FuncDataTemplate for flexible rendering.
  • Template reuse through resources and dynamic template assignment via ItemTemplate or auto-selection.

Quick Start

Register a DataTemplate for a ViewModel in Application.DataTemplates and reference it from a ContentControl to render the corresponding view.

Frequently Asked Questions about avalonia-data-templates

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define an Avalonia DataTemplate for a ListBox or ContentControl?

To define an Avalonia DataTemplate for a ListBox or ContentControl, register the template in Application.DataTemplates or set ItemTemplate and ContentTemplate directly on the control, enabling runtime-type matching to render the corresponding view model.

What's the best way to render hierarchical data in an Avalonia TreeView?

The best way to render hierarchical data in an Avalonia TreeView is using TreeDataTemplate, which supports hierarchical view model rendering and integrates with compiled bindings via x:DataType for type safety and performance.

How does compiled binding with x:DataType affect Avalonia DataTemplates?

Compiled binding with x:DataType improves Avalonia DataTemplate performance and type safety by resolving bindings at compile time, ensuring proper template scope resolution across app-level and per-control templates.

Can I use different templates for the same control based on data types in Avalonia?

Yes, you can use different templates for the same control by implementing IDataTemplate selectors or FuncDataTemplate, enabling dynamic template assignment and flexible rendering based on runtime object types.

When should I use app-level DataTemplates versus per-control templates in Avalonia?

Use app-level DataTemplates in Avalonia for consistent UI composition across multiple controls, and use per-control templates when you need isolated template scope resolution or specific rendering for a single control like a DataGrid.