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

Open
wants to merge 3 commits into
base: main
Choose a base branch
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

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

- fixes #28849
- fixes #28850
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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