Skip to content

[XSG] Fix Setter.Value property element lookup to be namespace-agnostic#34055

Open
StephaneDelcroix wants to merge 2 commits intomainfrom
fix/34039-xsg-setter-value-namespace
Open

[XSG] Fix Setter.Value property element lookup to be namespace-agnostic#34055
StephaneDelcroix wants to merge 2 commits intomainfrom
fix/34039-xsg-setter-value-namespace

Conversation

@StephaneDelcroix
Copy link
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description

Fixes #34039

When <Setter.Value> is used as a property element, GetValueNode() in SetterValueProvider.cs looked up the Value property only by specific namespace URIs ("" and MauiUri). When the property element used a different namespace URI, the lookup returned null. Since PR #33681 changed the null-return behavior to a skip sentinel, this caused the Setter to be removed from Variables entirely, preventing the .Add() call from being generated.

Root Cause

GetValueNode() checked only two specific namespace URIs:

node.Properties.TryGetValue(new XmlName("", "Value"), out valueNode)
node.Properties.TryGetValue(new XmlName(XamlParser.MauiUri, "Value"), out valueNode)

Property elements like <Setter.Value> inherit their namespace URI from the XML reader, which varies depending on the xmlns declaration used. When neither URI matched, GetValueNode() returned null, triggering the skip sentinel introduced in #33681 (for the OnPlatform case), which removed the Setter from Variables and suppressed the Setters.Add() call.

Fix

Made GetValueNode() namespace-agnostic by iterating all properties and matching on LocalName == "Value":

foreach (var prop in node.Properties)
{
    if (prop.Key.LocalName == "Value")
        return prop.Value;
}

Testing

  • Added SetterValueInTrigger unit test that reproduces the issue
  • Test fails without fix, passes with fix
  • Full SourceGen test suite: 189/192 pass (3 pre-existing AppThemeBinding failures unrelated to this change)

Fixes #34039

When <Setter.Value> is used as a property element with a namespace URI
other than MauiUri (e.g., MauiGlobalUri with implicit xmlns),
GetValueNode() failed to find it. Since PR #33681 changed the null
return to a skip sentinel, this caused the Setter to be removed from
Variables entirely, preventing the .Add() call from being generated.

The fix makes GetValueNode() iterate all properties matching
LocalName == "Value" instead of checking specific namespace URIs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 14, 2026 07:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a .NET MAUI XAML Source Generator (XSG) regression where Setter instances using the <Setter.Value> property element could be dropped (and therefore not added to Trigger.Setters) when implicit/alternative xmlns declarations caused the Value property element’s namespace URI to differ from the previously hard-coded lookups.

Changes:

  • Update SetterValueProvider.GetValueNode() to locate the Value property element by LocalName == "Value" regardless of namespace URI.
  • Add a SourceGen unit test reproducing the issue with implicit xmlns and verifying the generated code contains the Setters.Add(...) call.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Controls/src/SourceGen/SetterValueProvider.cs Makes <Setter.Value> lookup namespace-agnostic so XSG doesn’t drop setters when property-element namespaces vary.
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/SetterValueInTrigger.cs Adds a regression test covering <Setter.Value> inside a Trigger under implicit xmlns conditions.

…gger

Verifies that Setter with <Setter.Value> containing FontImageSource
inside a Style Trigger is correctly inflated across all XamlInflator
modes (Runtime, XamlC, SourceGen).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

XSG drops Trigger.Setters.Add() for Shell Tab Icons when using implicit xmlns - 10.0.40

1 participant