Skip to content

refactor: Centralize reuseable bindings and brushes - #448

Merged
w-ahmad merged 1 commit into
mainfrom
perf/reuse-resources
Oct 2, 2026
Merged

w-ahmad merged 1 commit into
mainfrom
perf/reuse-resources

Conversation

@w-ahmad

@w-ahmad w-ahmad commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Description

Cells, row headers, rows and column headers were each creating their own identical Binding and SolidColorBrush objects. That is a lot of redundant allocation when scrolling or virtualizing large tables.

This PR adds an internal SharedResources helper (src/Helpers/SharedResources.cs) that creates each of these objects once and reuses it:

  • TransparentBrush, for hidden grid lines in TableViewCell, TableViewColumnHeader, TableViewHeaderRow and TableViewRowPresenter.
  • FontFamilyBinding and FontSizeBinding, for TableView, where they are set on each row.
  • RowHeightBinding, RowMinHeightBinding and RowMaxHeightBinding, for cells (TableViewRow) and row headers (TableViewRowPresenter).
  • HeaderBinding, for column header content (TableViewHeaderRow).

The row-height bindings now point at TableView.RowHeight through RelativeSource.Self, where the old ones went through TableViewCell.TableView or TableViewRowHeader.TableView. Both types expose the same TableView property, so the resolved values are the same.

Each shared object is [ThreadStatic], because XAML objects can't be used from a thread other than the one that created them.

There is no intended behavior change.

Related Issue

Closes #

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
  • Unit / integration tests added or updated
  • Documentation updated to reflect changes
  • Code follows the project's coding conventions

Screenshots / Recordings

N/A, there are no visual changes.

Additional Notes

@w-ahmad w-ahmad changed the title centralize reuseable bindings and brushes refactor: Centralize reuseable bindings and brushes Sep 29, 2026
@w-ahmad
w-ahmad requested a balanced review from Copilot September 30, 2026 04:25

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.

Copilot review overview

🟡 Changes recommended

The shared name-based bindings are incompatible with the Native AOT changes explicitly assumed from PR #445.

Review effort: Balanced
Findings: 2 High severity

Open (2)
What changed in this PR

Centralizes reusable WinUI bindings and brushes to reduce allocations during table virtualization.

Changes:

  • Adds thread-local shared bindings and a transparent brush.
  • Updates rows, cells, and headers to consume shared resources.
  • However, shared name-based bindings conflict with PR #445’s Native AOT approach.
File Description
src/​Helpers/​SharedResources.cs Defines shared thread-local resources.
src/​TableView.cs Reuses row font bindings.
src/​TableViewRow.cs Reuses cell height bindings.
src/​TableViewRowPresenter.cs Reuses row-header bindings and brush.
src/​TableViewHeaderRow.cs Reuses header binding and brush.
src/​TableViewColumnHeader.cs Reuses the transparent brush.
src/​TableViewCell.cs Reuses the transparent brush.

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

/// Gets a binding to <see cref="RowHeight"/>, shared by every cell and row header.
/// </summary>
[field: ThreadStatic]
internal static Binding RowHeightBinding => field ??= new Binding { Path = new("TableView.RowHeight"), RelativeSource = new() { Mode = RelativeSourceMode.Self } };
/// Gets a binding to the column header, shared by every column header.
/// </summary>
[field: ThreadStatic]
internal static Binding HeaderBinding => field ??= new Binding { Path = new(nameof(TableViewColumn.Header)) };
@w-ahmad
w-ahmad merged commit ae77404 into main Oct 2, 2026
12 checks passed
@w-ahmad
w-ahmad deleted the perf/reuse-resources branch October 2, 2026 11:36
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.

2 participants