.NET MAUI 10 is the fifth major release of .NET MAUI, a cross-platform framework for building mobile and desktop apps.
It’s slated for a GA release during the .NET Conf, an annual virtual developer event, scheduled from Nov 11-13, 2025.
It’s packed with many quality of life improvements. The Global and Implicit Namespace for XAML feature is the pick of the lot.
To learn about the key features of .NET MAUI 10, check out this Overview article.
What’s Covered:
A Quick Intro to XAML:
- XAML is an acronym that stands for eXtensible Application Markup Language.
- It is an XML-based declarative markup language used to define UI in .NET apps.
- The XAML document is made of Elements and Attributes. It should have one top-level root element; otherwise, it is invalid.
- All XML namespaces ought to be defined as
xmlnsattributes of the root element. They should not be placed elsewhere in the document structure. - When declaring an element or attribute, and it is not part of the root namespace, a prefix becomes essential.
- This prefix must align with an XML namespace that is defined at the root element.
- The root namespace has no prefixes.
- Imagine namespace as a scope.
Sample XAML:
<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
x:Class="MyApp.Views.HomePage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="Home">
<Label
HorizontalOptions="Center"
Text="Hello .NET MAUI!!!"
VerticalOptions="Center" />
</ContentPage>
Here, ContentPage is the root node. Since, the root element is part of the root namespace, it has no prefix. To link the C# code-behind file, the XAML 2009 Spec defines the Class attribute. This attribute holds the fully qualified name of the C# type.
Here, the Class attribute is not part of the root namespace. Thus, it is necessary to define a prefix. It must associate the prefix, usually the x prefix, with the XAML 2009 Spec namespace. Whereas the Title attribute is part of the ContentPage node, hence without any prefix.
The root element doesn’t need to be from the root namespace; it can come from another namespace too.
<?xml version="1.0" encoding="UTF-8" ?>
<mct:Popup
x:Class="MyApp.Views.BusyPopup"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit">
<!-- Popup definition -->
</mct:Popup>
In real usage, the root element can become very messy. There are quite a lot of namespaces and their prefixes to manage. These include Models, ViewModels, Views, Controls, Converters, Third-Party Components, and so on.
.NET MAUI 10, attempts to resolve this messy root node issue by introducing Global and Implicit Namespace for XAML.
The HTTP-based XML namespace aggregates multiple CLR namespaces into one. This avoids bloating the root element, even in simple UI definitions. This is the foundation of these new features.
Global Namespace:
Like other XAML-based UI frameworks, .NET MAUI defined a common HTTP-based namespace. It globed the commonly used CLR namespaces of Framework types from the initial version.
This older namespace is still valid to use, but it offers no real advantage.
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
A new HTTP namespace is being defined to let users map custom CLR namespaces in addition. This is the MAUI global namespace.
xmlns="http://schemas.microsoft.com/dotnet/maui/global"
Page Sample:
Before:
<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
x:Class="MauiApp2.Views.SamplePage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:m="clr-namespace:MauiApp2.Models"
xmlns:vm="clr-namespace:MauiApp2.ViewModels"
x:DataType="vm:SampleViewModel">
<ContentPage.BindingContext>
<vm:SampleViewModel />
</ContentPage.BindingContext>
<StackLayout
BindableLayout.ItemsSource="{Binding AppModels}"
HorizontalOptions="Center"
VerticalOptions="Center">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="m:AppModel">
<Label Text="{Binding Name}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</ContentPage>
After:
<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
x:Class="MauiApp2.Views.SamplePage"
xmlns="http://schemas.microsoft.com/dotnet/maui/global"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:DataType="SampleViewModel">
<ContentPage.BindingContext>
<SampleViewModel />
</ContentPage.BindingContext>
<StackLayout
BindableLayout.ItemsSource="{Binding AppModels}"
HorizontalOptions="Center"
VerticalOptions="Center">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="AppModel">
<Label Text="{Binding Name}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</ContentPage>
The XAML has become clean and concise. Now the root node has only two namespaces. All those types are defined like they’re part and parcel of the document.
Workings:
The XmlnsDefinition attribute allows mapping CLR namespaces to an XML namespace in URI format.
.NET MAUI source generator includes mappings for common Framework types and lets users glob custom namespaces in their projects.
// CLR Namespaces
// Root namespace
[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/maui/global", "MyApp")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/maui/global", "MyApp.Models")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/maui/global", "MyApp.ViewModels")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/maui/global", "MyApp.Views")]
// XAML Namespaces
// .NET MAUI Community Toolkit
[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/maui/global", "http://schemas.microsoft.com/dotnet/2022/maui/toolkit")]
Add these assembly attributes to any C# file, say Imports.cs, and adjust the CLR namespaces for your project. Quite like managing the C# global usings feature.
Update the root namespace of the XAML document to refer MAUI global. Then the types within these namespaces can be used without any prefix.
Earlier Popup sample, now updated:
<?xml version="1.0" encoding="UTF-8" ?>
<Popup
x:Class="MyApp.Views.BusyPopup"
xmlns="http://schemas.microsoft.com/dotnet/maui/global"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<!-- Popup definition -->
</Popup>
Implicit Namespace:
If even those two namespaces seem like an overhead, then this is the answer.
When opted, .NET MAUI 10 automatically adds those two namespaces for you. This feature is still in preview.
You can opt-in to the feature in two different ways.
- Via the project file.
- As assembly attributes.
I prefer the latter as it is easy to manage.
In the project file: (only the relevant nodes are shown):
<Project>
<PropertyGroup>
<!-- First, enable preview feature flag -->
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<!-- Then, opt-in for the implicit namespace feature -->
<DefineConstants>$(DefineConstants);MauiAllowImplicitXmlnsDeclaration</DefineConstants>
</PropertyGroup>
</Project>
As assembly attributes:
[assembly: System.Runtime.Versioning.RequiresPreviewFeatures]
[assembly: Microsoft.Maui.Controls.Xaml.Internals.AllowImplicitXmlnsDeclaration]
Earlier Popup sample, with only elements and attributes, no namespaces.
But remember, the XAML 2009 Spec nodes requires that x prefix.
<?xml version="1.0" encoding="UTF-8" ?>
<Popup x:Class="MyApp.Views.BusyPopup">
<!-- Popup definition -->
</Popup>
Type Resolution:
When using the implicit namespace feature, it’s common to encounter the same type name in different namespaces. This can cause name collisions. In these scenarios, you can use a global prefix to avoid confusion. This is achieved with the use of XmlnsPrefix attribute.
// Since this attribute type name itself is in two namespaces, it’s necessary to disambiguate it first.
using XmlnsPrefixAttribute = Microsoft.Maui.Controls.XmlnsPrefixAttribute;
[assembly: XmlnsPrefix("MyApp.Models", "m")]
[assembly: XmlnsPrefix("MyApp.ViewModels", "vm")]
[assembly: XmlnsPrefix("http://schemas.microsoft.com/dotnet/2022/maui/toolkit", "mct")]
Any node with the vm prefix will be resolved using the MyApp.ViewModels namespace.
It’s to be noted that the Framework types are defined with the maui prefix.
Templates Support:
When creating .NET MAUI projects using All-in-One Templates targeting .NET 10, all XAML files will be generated with the MAUI global namespace. These assembly attributes are added to the Imports.cs source file in the project root.
The XAML item templates have support for both features via opt-in parameters.
To know more about this, consult this What’s New in All-in-One Templates v7.9 article.
Update: Like the Global namespace for .NET MAUI 10 projects, the option to use the Implicit namespace is in progress. It will be included in the upcoming Templates release. It will be an opt-in parameter, like the XAML Item templates.
Further Reading:
Happy coding. Stay connected as we continue to learn and share the experiences from this exciting journey of being a .NET developer.
2 replies on “What’s New in .NET MAUI 10: Global and Implicit Namespaces for XAML”
[…] This feature is discussed in a detailed article. […]
[…] this Global and Implicit Namespaces article to know more about this new […]