This sample demonstrates how to use the TreeDataGrid component to display data in a flat "DataGrid"-like layout.
It uses the MVVM pattern and sets up a FlatTreeDataGridSource in MainWindowViewModel which is exposed to the view via a property.
This FlatTreeDataGridSource sets up a grid which displays a list of countries along with various details about them.
- Multiple Column Types: The sample shows how to define different column types:
- A row header column for row numbers. Together with the
FrozenColumnCountproperty, this keeps the row numbers visible during horizontal scrolling. - Read/write text columns with the
Countryname column - Template columns with custom cell and edit templates for the
Regioncolumn - Read-only text columns for data like
PopulationandArea - Customized text columns with alignment and size constraints for the
GDPcolumn
- A row header column for row numbers. Together with the
- Text Search: Enabling text search functionality for specific columns
- Custom Data Templates: Demonstrating how to use data templates for displaying and editing cell content
- Row Drag & Drop: Auto drag-drop functionality for rows with
AutoDragDropRows="True" - Three-state Sorting: Enabling three-state sorting (ascending/descending/none) with
AllowTriStateSorting="True"
- Alternating Row Colors: Implementing alternating background colors for rows using
RowTheme - 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
- Proper MVVM implementation showing how to bind a collection of domain objects (Countries) to the TreeDataGrid
- Clean separation of concerns between data (Country model), presentation logic (MainWindowViewModel), and UI (MainWindow)