Skip to content

feat: Add row numbering to the row header area - #426

Open
w-ahmad wants to merge 4 commits into
mainfrom
feat/row-numbers
Open

feat: Add row numbering to the row header area#426
w-ahmad wants to merge 4 commits into
mainfrom
feat/row-numbers

Conversation

@w-ahmad

@w-ahmad w-ahmad commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Description

Adds a ShowRowNumbers option that displays each row's number in a dedicated TextBlock at the very start of the row header area. The number reflects the row's real, stable position among all rows — it does not renumber when a group is collapsed and hides other rows, unlike a naive count of what's currently visible.

Key points:

  • New public API: TableView.ShowRowNumbers (bool, default false) and TableViewRow.RowNumber (1-based int). RowNumber is real (accounts for hidden/collapsed rows) only while grouping is active, so the common ungrouped case stays cheap.
  • Own column, own space: the row number lives in a new Grid column inserted before the row header and the row-details expander chevron in TableViewRowPresenter's template, so it never overlaps or steals space from RowHeaderTemplate, RowHeaderTemplateSelector, or the details toggle.
  • Themeable: new TableViewRowNumberFontSize, TableViewRowNumberForeground, TableViewRowNumberMargin, and TableViewRowNumberMinWidth resources across the Light, Dark, and HighContrast dictionaries.
  • TableViewRowHeader.Tag is now actually set to the row number, so a custom RowHeaderTemplate can bind to it via {Binding Tag, RelativeSource={RelativeSource Mode=TemplatedParent}} — this was already documented but had no backing implementation.
  • Accessibility: automation peers ("Row N" announcements on TableViewRow, TableViewCell, and TableViewRowHeader) now use the real number when ShowRowNumbers is enabled, keeping the announced and visible numbers consistent.
  • Added a ShowRowNumbers toggle to the Grouping sample page to make the real-vs-display distinction visible: collapsing a group no longer compacts the remaining numbers.

Related Issue

Closes #282

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 📝 Documentation update
  • ♻️ Refactor
  • 🧪 Test
  • 🔧 Chore / maintenance

Checklist

  • This PR is not from my main branch
  • Tested with WinUI target
  • Tested with Uno Platform target (builds clean on the non-Windows target; not run/verified visually)
  • Unit / integration tests added or updated
  • Documentation updated to reflect changes
  • Code follows the project's coding conventions

Screenshots / Recordings

image

Additional Notes

Real-index math is only invoked while grouping is active (CollectionView.IndexOfSourceItem, an O(n) lookup over the filtered+sorted source list); the ungrouped path stays O(1) via the existing display index. Full test suite passes (356/356) via vstest.console.exe against the real hosted app, including 7 new tests covering grouped/collapsed numbering, visibility toggling, and the Tag binding.

w-ahmad and others added 4 commits August 26, 2026 15:53
Demonstrates the new row-numbering feature: a toggle on the Grouping
page (to show numbers staying real across a group collapse) and
ShowRowNumbers enabled by default on the Overview page.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Collection mutations and duplicate items can produce incorrect numbers, while independently sized row-number columns can misalign rows.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds configurable row numbering to TableView, including grouped-row stability, theming, accessibility, documentation, samples, and tests.

Changes:

  • Introduces ShowRowNumbers and RowNumber.
  • Adds themed row-number rendering and automation support.
  • Documents and tests grouped numbering behavior.
File summaries
File Description
tests/TableViewRowNumberingTests.cs Tests row-number behavior and visibility.
tests/CollectionViewTests.cs Tests stable source indexing.
src/Themes/TableViewRowPresenter.xaml Adds the row-number column.
src/Themes/Resources.xaml Defines row-number theme resources.
src/TableViewRowPresenter.cs Updates row-number text and visibility.
src/TableViewRow.cs Exposes RowNumber.
src/TableView.Properties.cs Adds ShowRowNumbers.
src/TableView.cs Refreshes and calculates row numbers.
src/ItemsSource/CollectionView.cs Adds full-source item lookup.
src/AutomationPeers/TableViewRowHeaderAutomationPeer.cs Announces stable row numbers.
src/AutomationPeers/TableViewRowAutomationPeer.cs Updates row automation names.
src/AutomationPeers/TableViewCellAutomationPeer.cs Updates cell automation names.
samples/WinUI.TableView.SampleApp/Pages/OverviewPage.xaml Demonstrates row numbers.
samples/WinUI.TableView.SampleApp/Pages/GroupingPage.xaml Adds a numbering toggle.
docs/docs/row-headers.md Documents row numbering and theming.
Review details
  • Files reviewed: 15/15 changed files
  • Comments generated: 6
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/TableView.cs
foreach (var row in _rows)
{
row.RowPresenter?.SetGroupIndent();
row.RowPresenter?.SetRowNumber();

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="RowNumberColumn" Width="Auto" />
/// </summary>
internal int IndexOfSourceItem(object? item)
{
return item is null ? -1 : _groupingSourceItems.IndexOf(item);
MinWidth="{ThemeResource TableViewRowNumberMinWidth}"
Margin="{ThemeResource TableViewRowNumberMargin}"
FontSize="{ThemeResource TableViewRowNumberFontSize}"
Foreground="{ThemeResource TableViewRowNumberForeground}" />
Comment thread src/TableViewRow.cs

RowPresenter?.InvalidateMeasure(); // The cells presenter does not measure every time.
TableView?.EnsureAlternateRowColors();
TableView?.RefreshRowNumbers();
Description="Here's a preview of how the default implementation of the WinUI TableView will look, showcasing its standard layout, structure, and features.">
<controls:SamplePresenter.Example>
<tv:TableView ItemsSource="{Binding Items}" />
<tv:TableView ItemsSource="{Binding Items}" ShowRowNumbers="True" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto Row Number field

2 participants