Implement TableView#21511
Conversation
|
You can test this PR using the following package version. |
| <Border Background="{DynamicResource SystemControlBackgroundChromeMediumBrush}" | ||
| Padding="{DynamicResource TableViewRowPadding}" | ||
| DockPanel.Dock="Top"> | ||
| <TableViewColumnHeadersPresenter /> | ||
| </Border> |
There was a problem hiding this comment.
Can't TableViewColumnHeadersPresenter draw its own background and set padding? Background then can be defined on TableViewColumnHeadersPresenter theme directy.
Both changes should make re-styling easier.
There was a problem hiding this comment.
We need to implement Padding specifically on that panel, which would be a bit unexpected. Users still won't be able to customize things such as BorderBrush, BorderThickness, etc., unless we add them all to the TableViewColumnHeadersPresenter.
We can either:
- Keep it as is, the template isn't that hard to change (I can add a
Nameto theBorderso it's easier to refer in styles). - Add a new templated control dedicated to that purpose, e.g.
TableViewColumnHeadersRowcontaining the presenter. This solution expands the public API, but is similar to theRow/Presentertypes we already have for normal rows.
|
After recent surprises with logical/visual tree inconsistences in other controls, can we check how it is for this control? Visual tree should be natural, as it is defined by templates. Note, ":nth-child" handling is an extra complication here - we might end up adding RowsPresenter for consistency. |
The cells weren't part of the logical tree, I've added them. The tree now looks like this: Note: as you mentioned in the linked issue, having the column headers in the logical tree breaks Whatever we do, |
|
You can test this PR using the following package version. |
|
Yeah, current row-only solution is good to me |
|
It is not clear why a summary line is not made, even without any bells and whistles and even without automatic calculation; it is needed in 70% of cases. |
|
@Bobsoftru what do you mean by summary line? A special row on the bottom with some sort of aggregation per cell? If so, it should be possible to implement one in user code. |

What does the pull request do?
This PR implements a tabular view for data. It bridges the gap between a simple
ListBoxand a fully fledgedDataGrid/TreeDataGrid, for read-only data. See #21237 for details.The component is fully unit tested.
Features
ControlThemefor header and cellsAPI diff
namespace Avalonia.Controls { + public class TableView : ListBox + { + public static readonly StyledProperty<bool> CanResizeColumnsProperty; + public static readonly DirectProperty<TableView, AvaloniaList<TableViewColumn>?> ColumnsProperty; + public TableView(); + public bool CanResizeColumns { get; set; } + public AvaloniaList<TableViewColumn>? Columns { get; set; } + } + public class TableViewCell : ContentControl + { + public static readonly DirectProperty<TableViewCell, TableViewColumn?> ColumnProperty; + public TableViewCell(); + public TableViewColumn? Column { get; } + } + public class TableViewColumn : Avalonia.StyledElement + { + public static readonly DirectProperty<TableViewColumn, double> ActualWidthProperty; + public static readonly StyledProperty<BindingBase?> BindingProperty; + public static readonly DirectProperty<TableViewColumn, bool> CanEffectivelyResizeProperty; + public static readonly StyledProperty<bool?> CanResizeProperty; + public static readonly StyledProperty<IDataTemplate?> CellTemplateProperty; + public static readonly StyledProperty<ControlTheme?> CellThemeProperty; + public static readonly StyledProperty<object?> HeaderProperty; + public static readonly StyledProperty<IDataTemplate?> HeaderTemplateProperty; + public static readonly StyledProperty<ControlTheme?> HeaderThemeProperty; + public static readonly StyledProperty<HorizontalAlignment> HorizontalContentAlignmentProperty; + public static readonly DirectProperty<TableViewColumn, TableView?> TableViewProperty; + public static readonly StyledProperty<GridLength> WidthProperty; + public TableViewColumn(); + public double? ActualWidth { get; } + public BindingBase? Binding { get; set; } + public bool CanEffectivelyResize { get; } + public bool? CanResize { get; set; } + public IDataTemplate? CellTemplate { get; set; } + public ControlTheme? CellTheme { get; set; } + public object? Header { get; set; } + public IDataTemplate? HeaderTemplate { get; set; } + public ControlTheme? HeaderTheme { get; set; } + public HorizontalAlignment? HorizontalContentAlignment { get; set; } + public TableView? TableView { get; } + public GridLength Width { get; set; } + } + public class TableViewColumnHeader : ContentControl + { + public static readonly DirectProperty<TableViewColumnHeader, TableViewColumn?> ColumnProperty; + public TableViewColumnHeader(); + public TableViewColumn? Column { get; } + } + public class TableViewRow : ListBoxItem + { + public TableViewRow(); + } } namespace Avalonia.Controls.Presenters { + public class TableViewColumnHeadersPresenter : Panel + { + public TableViewColumnHeadersPresenter(); + } + public class TableViewCellsPresenter : Panel + { + public TableViewCellsPresenter(); + } }(
protected overridemembers are excluded for brevity)Fixed issues