microsoft / microsoft/microsoft-ui-xaml

Add Support for Global and Implicit XML Namespaces in WinUI XAML (parity with .NET MAUI)

Open
#10,616 1 comment 6 reactions 0 assignees View on GitHub
needs-triage
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

Recently, the .NET MAUI team has added support for this exact feature in .NET 10, as described in their release notes. It introduces Global XML Namespaces and Implicit XML Namespaces for XAML, which dramatically improves developer experience and reduces boilerplate in XAML files.

**[XAML Global Namespaces](https://github.com/dotnet/core/blob/main/release-notes/10.0/preview/preview5/dotnetmaui.md#xaml-global-namespaces)**

In your projects you can now glob together XML-namespaces into a new global namespace xmlns="http://schemas.microsoft.com/dotnet/maui/global", and use them without prefixes. The .NET MAUI namespace is included already.

By convention the new project template creates a file GlobalXmlns.cs.

```
[assembly: XmlnsDefinition(
"http://schemas.microsoft.com/dotnet/maui/global",
"MyApp.Views")]
[assembly: XmlnsDefinition(
"http://schemas.microsoft.com/dotnet/maui/global",
"MyApp.Controls")]
[assembly: XmlnsDefinition(
"http://schemas.microsoft.com/dotnet/maui/global",
"MyApp.Converters")]
[assembly: XmlnsDefinition(
"http://schemas.microsoft.com/dotnet/maui/global",
"http://schemas.syncfusion.com/maui/toolkit")]
```

You can then use anything in those namespaces like you do .NET MAUI controls, without prefix.

```xml

```

The x namespace cannot be globbed into the global namespace since it's used for parsing.

**[XAML Implicit Namespaces](https://github.com/dotnet/core/blob/main/release-notes/10.0/preview/preview5/dotnetmaui.md#xaml-implicit-namespaces)**

You can opt-in to this feature by adding the following to your project file. As of now, turning this on may cause errors to be reported by various XAML tools.

```

$(DefineConstants);MauiAllowImplicitXmlnsDeclaration
true

```
With this change you can also eliminate xmlns and xmlns:x from XAML files.
```

```
In this usage:

- the default xmlns is the global one
- the x: prefix is added by default
- all xmlns with a XmlnsPrefix are also accessible with their prefix, even if they are included in the global xmlns. These are useful for disambiguating a name. For example, the maui: prefix points to the maui xmlns.
- you still need to use the x: prefix (e.g. x:Class, x:DataType), but you don't have to declare it

This feature has been requested several times in the past by the community, But they turned into discussions and reached no conclusion.:

https://github.com/microsoft/microsoft-ui-xaml/discussions/10293

https://github.com/microsoft/WindowsAppSDK/discussions/2946

Contributor guide

Open the contributing guide

Research direction

Start by reading the linked .NET MAUI release notes and the prior Microsoft UI XAML and Windows App SDK discussions to understand the proposed global and implicit namespace behavior. Identify the WinUI XAML namespace-resolution entry points and relevant tests; done means WinUI supports the documented global and opt-in implicit namespace scenarios without requiring the existing declarations.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.