Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Controls.TreeDataGrid" Version="11.2.0" />
<PackageReference Include="Avalonia.Controls.TreeDataGrid" Version="11.3.0-beta4" />
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="$(AvaloniaVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using Avalonia.Controls;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Selection;
using FlatTreeDataGridSample.Models;

namespace FlatTreeDataGridSample.ViewModels;
Expand All @@ -26,6 +27,11 @@ public MainWindowViewModel()
{
Columns =
{
// Define a row header column for row numbering. This can be made to be always
// visible when scrolling horizontally by setting FrozenColumnCount = 1 on the
// TreeDataGrid.
new RowHeaderColumn<Country>(),

// Define a read/write text column for the country name with text search enabled.
new TextColumn<Country, string>(
"Country",
Expand All @@ -52,6 +58,7 @@ public MainWindowViewModel()
}
};

Source.Selection = new TreeDataGridCellSelectionModel<Country>(Source);
MaxPopulation = _data.Max(x => x.Population);
}

Expand Down
1 change: 1 addition & 0 deletions TreeDataGrid/FlatTreeDataGridSample/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Source="{Binding Source}"
AllowTriStateSorting="True"
AutoDragDropRows="True"
FrozenColumnCount="1"
CellPrepared="countries_CellPrepared"
CellClearing="countries_CellClearing">
<TreeDataGrid.Resources>
Expand Down
2 changes: 2 additions & 0 deletions TreeDataGrid/FlatTreeDataGridSample/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This `FlatTreeDataGridSource` sets up a grid which displays a list of countries

### Column Configuration
- **Multiple Column Types**: The sample shows how to define different column types:
- A row header column for row numbers. Together with the `FrozenColumnCount` property, this keeps the row numbers visible during horizontal scrolling.
- Read/write text columns with the `Country` name column
- Template columns with custom cell and edit templates for the `Region` column
- Read-only text columns for data like `Population` and `Area`
Expand All @@ -26,6 +27,7 @@ This `FlatTreeDataGridSource` sets up a grid which displays a list of countries
- **Column Header Styling**: Custom styling for specific column headers (last column appears in bold)
- **Cell Styling**: Custom styling for specific cells (last column cells appear in bold)
- **Custom Templates**: Both display and edit templates for the Region column, including a ComboBox for selection
- **Frozen Columns**: Keeping certain columns fixed during horizontal scrolling by setting `TreeDataGrid.FrozenColumnCount`

### Data Binding
- Proper MVVM implementation showing how to bind a collection of domain objects (Countries) to the TreeDataGrid
Expand Down