feat: Add row numbering to the row header area - #426
Open
w-ahmad wants to merge 4 commits into
Open
Conversation
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>
w-ahmad
force-pushed
the
feat/row-numbers
branch
from
August 26, 2026 11:05
2e00f82 to
1d0cc3d
Compare
Contributor
There was a problem hiding this comment.
🟡 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
ShowRowNumbersandRowNumber. - 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.
| 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}" /> |
|
|
||
| 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" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a
ShowRowNumbersoption that displays each row's number in a dedicatedTextBlockat 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:
TableView.ShowRowNumbers(bool, defaultfalse) andTableViewRow.RowNumber(1-basedint).RowNumberis real (accounts for hidden/collapsed rows) only while grouping is active, so the common ungrouped case stays cheap.Gridcolumn inserted before the row header and the row-details expander chevron inTableViewRowPresenter's template, so it never overlaps or steals space fromRowHeaderTemplate,RowHeaderTemplateSelector, or the details toggle.TableViewRowNumberFontSize,TableViewRowNumberForeground,TableViewRowNumberMargin, andTableViewRowNumberMinWidthresources across the Light, Dark, and HighContrast dictionaries.TableViewRowHeader.Tagis now actually set to the row number, so a customRowHeaderTemplatecan bind to it via{Binding Tag, RelativeSource={RelativeSource Mode=TemplatedParent}}— this was already documented but had no backing implementation.TableViewRow,TableViewCell, andTableViewRowHeader) now use the real number whenShowRowNumbersis enabled, keeping the announced and visible numbers consistent.ShowRowNumberstoggle 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
Checklist
mainbranchScreenshots / Recordings
Additional Notes
Real-index math is only invoked while grouping is active (
CollectionView.IndexOfSourceItem, anO(n)lookup over the filtered+sorted source list); the ungrouped path staysO(1)via the existing display index. Full test suite passes (356/356) viavstest.console.exeagainst the real hosted app, including 7 new tests covering grouped/collapsed numbering, visibility toggling, and theTagbinding.