XAML Usage Overview

TreeDataGrid can now be configured directly in XAML with ItemsSource and declarative columns. This is the recommended path when your columns, templates, and bindings naturally belong in markup.

Theme Setup

<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             x:Class="MyApp.App">
  <Application.Styles>
    <FluentTheme/>
    <StyleInclude Source="avares://Avalonia.Controls.TreeDataGrid/Themes/Fluent.axaml"/>
  </Application.Styles>
</Application>
<TreeDataGrid ItemsSource="{Binding People}">
  <TreeDataGridTextColumn Header="First Name"
                          Binding="{Binding FirstName}"/>
  <TreeDataGridTextColumn Header="Last Name"
                          Binding="{Binding LastName}"/>
</TreeDataGrid>

When to Use Source Instead

Use the code-behind Source approach when you need:

  • Filter and RefreshFilter
  • Expand, Collapse, ExpandAll, and CollapseAll
  • more complex runtime composition of columns

Article Map