diff --git a/src/DynamicTreeDataGrid/Columns/DynamicCheckBoxColumn.cs b/src/DynamicTreeDataGrid/Columns/DynamicCheckBoxColumn.cs new file mode 100644 index 0000000..6fa632e --- /dev/null +++ b/src/DynamicTreeDataGrid/Columns/DynamicCheckBoxColumn.cs @@ -0,0 +1,56 @@ +using System.Linq.Expressions; + +using Avalonia.Controls; +using Avalonia.Controls.Models.TreeDataGrid; +using Avalonia.Experimental.Data; + +namespace DynamicTreeDataGrid.Columns; + +public class DynamicCheckBoxColumn : CheckBoxColumn + where TModel : class { + /// + /// Initializes a new instance of the class. + /// + /// The column header. + /// + /// An expression which given a row model, returns a boolean cell value for the column. + /// + /// + /// A method which given a row model and a cell value, writes the cell value to the + /// row model. If not supplied then the column will be read-only. + /// + /// + /// The column width. If null defaults to . + /// + /// Additional column options. + public DynamicCheckBoxColumn(object? header, + Expression> getter, + Action? setter = null, + GridLength? width = null, + CheckBoxColumnOptions? options = null) : base(header, getter, setter, width, + options) { } + + /// + /// Initializes a new instance of the class that + /// displays a three-state check box. + /// + /// The column header. + /// + /// An expression which given a row model, returns a nullable boolean cell value for the + /// column. + /// + /// + /// A method which given a row model and a cell value, writes the cell value to the + /// row model. If not supplied then the column will be read-only. + /// + /// + /// The column width. If null defaults to . + /// + /// Additional column options. + public DynamicCheckBoxColumn(object? header, + Expression> getter, + Action? setter = null, + GridLength? width = null, + CheckBoxColumnOptions? options = null) : base(header, getter, setter, width, + options ?? new CheckBoxColumnOptions()) { } +} diff --git a/src/DynamicTreeDataGrid/Columns/DynamicTemplateColumn.cs b/src/DynamicTreeDataGrid/Columns/DynamicTemplateColumn.cs new file mode 100644 index 0000000..1f3394f --- /dev/null +++ b/src/DynamicTreeDataGrid/Columns/DynamicTemplateColumn.cs @@ -0,0 +1,21 @@ +using Avalonia.Controls; +using Avalonia.Controls.Models.TreeDataGrid; +using Avalonia.Controls.Templates; + +namespace DynamicTreeDataGrid.Columns; + +public class DynamicTemplateColumn : TemplateColumn { + public DynamicTemplateColumn(object? header, + IDataTemplate cellTemplate, + IDataTemplate? cellEditingTemplate = null, + GridLength? width = null, + TemplateColumnOptions? options = null) : base(header, cellTemplate, + cellEditingTemplate, width, options) { } + + public DynamicTemplateColumn(object? header, + object cellTemplateResourceKey, + object? cellEditingTemplateResourceKey = null, + GridLength? width = null, + TemplateColumnOptions? options = null) : base(header, cellTemplateResourceKey, + cellEditingTemplateResourceKey, width, options) { } +} diff --git a/src/DynamicTreeDataGrid/Columns/DynamicTextColumn.cs b/src/DynamicTreeDataGrid/Columns/DynamicTextColumn.cs new file mode 100644 index 0000000..05fd7dd --- /dev/null +++ b/src/DynamicTreeDataGrid/Columns/DynamicTextColumn.cs @@ -0,0 +1,47 @@ +using System.Linq.Expressions; + +using Avalonia.Controls; +using Avalonia.Controls.Models.TreeDataGrid; + +namespace DynamicTreeDataGrid.Columns; + +public class DynamicTextColumn : TextColumn + where TModel : class { + /// + /// Initializes a new instance of the class. + /// + /// The column header. + /// + /// An expression which given a row model, returns a cell value for the column. + /// + /// + /// The column width. If null defaults to . + /// + /// Additional column options. + public DynamicTextColumn(object? header, + Expression> getter, + GridLength? width = null, + TextColumnOptions? options = null) : base(header, getter, width, options) { } + + /// + /// Initializes a new instance of the class. + /// + /// The column header. + /// + /// An expression which given a row model, returns a cell value for the column. + /// + /// + /// A method which given a row model and a cell value, writes the cell value to the + /// row model. + /// + /// + /// The column width. If null defaults to . + /// + /// Additional column options. + public DynamicTextColumn(object? header, + Expression> getter, + Action setter, + GridLength? width = null, + TextColumnOptions? options = null) : base(header, getter, setter, width, + options ?? new()) { } +}