Skip to content

[X] implicit xmlns declarations #29181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

StephaneDelcroix
Copy link
Contributor

@StephaneDelcroix StephaneDelcroix commented Apr 24, 2025

Description of Change

Make the default xmlns implicitely pointing to maui default xmlns pre-load all available XmlsPrefixes for use

Enable this feature by adding this into the .csproj

  <PropertyGroup>
    <DefineConstants>$(DefineConstants);MauiAllowImplicitXmlnsDeclaration</DefineConstants>
    <EnablePreviewFeatures>true</EnablePreviewFeatures>
  </PropertyGroup>

Issues Fixed

@Copilot Copilot AI review requested due to automatic review settings April 24, 2025 20:37
@StephaneDelcroix StephaneDelcroix requested a review from a team as a code owner April 24, 2025 20:37
Copy link
Contributor

@Copilot 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 implements support for implicit xmlns declarations by pre-loading available XmlnsPrefix attributes and updating various XAML parsing and code-behind generation routines. Key changes include:

  • Adding implicit namespace support in XamlParser, XamlLoader, and related build tasks.
  • Refactoring CodeBehindGenerator to incorporate new assembly cache information (including xmlns prefixes) and updated type signatures.
  • Updating and adding test cases to verify the new implicit xmlns behavior.

Reviewed Changes

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

Show a summary per file
File Description
src/Controls/tests/Xaml.UnitTests/HRTests.cs Adds a new SetUp method to reset Application.Current for test isolation.
src/Controls/tests/Xaml.UnitTests/GlobalXmlns.xaml.cs Introduces tests for validating behavior when implicit xmlns declarations are used.
src/Controls/tests/SourceGen.UnitTests/SourceGenXamlTests.cs Adds tests verifying global namespace handling and behavior when non-XAML is provided.
src/Controls/src/Xaml/XamlParser.cs Adds GetXmlnsPrefixAttributes to return preloaded xmlns prefixes using new array initializer syntax.
src/Controls/src/Xaml/XamlParser.Namespaces.cs Introduces DefaultImplicitUri to serve as the default implicit xmlns.
src/Controls/src/Xaml/XamlLoader.cs Updates XmlNamespaceManager initialization to include the default implicit xmlns and additional prefixes.
src/Controls/src/SourceGen/CodeBehindGenerator.cs Refactors methods (including ComputeXamlProjectItem and TryParseXaml) to support the new assembly caches and adjust type signatures accordingly.
src/Controls/src/Core/Properties/AssemblyInfo.cs Adds an assembly attribute for the XAML 2009 namespace prefix.
src/Controls/src/Build.Tasks/* Updates XAML parsing tasks to use module-specific xmlns prefix resolution.
Files not reviewed (3)
  • Microsoft.Maui-vscode.sln: Language not supported
  • src/Controls/src/SourceGen/Controls.SourceGen.csproj: Language not supported
  • src/Controls/tests/Xaml.UnitTests/GlobalXmlns.xaml: Language not supported
Comments suppressed due to low confidence (1)

src/Controls/src/SourceGen/CodeBehindGenerator.cs:142

  • The variable 'text' is not defined in this scope. It appears that the content from the ProjectItem should be used instead, for example by referencing projectItem.Text.
using var reader = XmlReader.Create(new StringReader(text.ToString(),

@samhouts samhouts added the area-xaml XAML, CSS, Triggers, Behaviors label Apr 24, 2025
@StephaneDelcroix StephaneDelcroix force-pushed the dev/stdelc/implicitxmlns branch 3 times, most recently from fef2947 to a146b52 Compare May 19, 2025 10:16
Make the default xmlns implicitely pointing to maui default xmlns
pre-load all available XmlsPrefixes for use

the capability is disabled by default, and you need to opt-in

- fixes #28849
- fixes #28850
- fixes #28847
@StephaneDelcroix
Copy link
Contributor Author

closing in favour of #29579

@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pre-defined xmlns prefixes make the default xmlns declaration optional Implicit global xmlns
2 participants