Skip to content

Fix null Content.Name binding errors - #5503

Open
Sébastien Duquette (sduquette-devolutions) wants to merge 1 commit into
mainfrom
fix-null-name-binding
Open

Sébastien Duquette (sduquette-devolutions) wants to merge 1 commit into
mainfrom
fix-null-name-binding

Conversation

@sduquette-devolutions

Copy link
Copy Markdown
Contributor

The message "An error occurred binding 'Name' to 'Content.Name' at 'Content': 'Value is null.'" appeared multiple times in the console when starting the app. The cause was a global style in Styles.Common.axaml. It copies the automation name (the accessible name used by screen readers) from each DataGridCell's content. The DataGrid reuses cells as you scroll, so the content is briefly null, and the old binding path then logged "Value is null."

I replaced it with a binding that tolerates a null content. It uses a new converter, Converters/AutomationNameOfContentConverter.cs. The cell's accessible name is now read once from the content instead of tracking later changes to it. The templates set it statically, so that shouldn't matter in practice.

The message "An error occurred binding 'Name' to 'Content.Name' at
'Content': 'Value is null.'" appeared multiple times in the console
when starting the app. The cause was a global style in `Styles.Common.axaml`.
It copies the automation name (the accessible name used by screen readers)
from each `DataGridCell`'s content. The DataGrid reuses cells as you scroll,
so the content is briefly null, and the old binding path then logged "Value is null."

I replaced it with a binding that tolerates a null content. It uses a new converter,
`Converters/AutomationNameOfContentConverter.cs`. The cell's accessible name is now
read once from the content instead of tracking later changes to it. The templates
set it statically, so that shouldn't matter in practice.

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

The new binding can retain stale names and misses asynchronous automation-name updates.

2 open findings
What changed in this PR

Updates DataGrid automation-name binding to tolerate recycled cells with null content.

Changes:

  • Adds an automation-name converter.
  • Uses it in the global DataGridCell style.
File Description
AutomationNameOfContentConverter.cs Resolves automation names from cell content.
Styles.Common.axaml Applies the converter globally to DataGrid cells.

🧠 Review effort: Balanced


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


<Style Selector="DataGridCell">
<Setter Property="automation:AutomationProperties.Name" Value="{Binding $self.((Control)Content).(automation:AutomationProperties.Name)}"/>
<Setter Property="automation:AutomationProperties.Name" Value="{Binding $self.Content, Converter={x:Static conv:AutomationNameOfContentConverter.Instance}}"/>
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
=> value is Control control
? AutomationProperties.GetName(control)
: BindingOperations.DoNothing;

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants