Skip to content

Global Xmlns is not working for DataTemplate #31765

@DM-98

Description

@DM-98

Description

When adding Views into GlobalXmlns.cs like this:

[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/maui/global", "Faluf.CodexUI.MAUI.Views")]

It doesn't allow, in my AppShell.xaml, to remove the prefix views: for choosing the page. For example:

<?xml version="1.0" encoding="UTF-8" ?>
<Shell 
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="Faluf.CodexUI.MAUI.AppShell">

    <ShellContent Title="Home" ContentTemplate="{DataTemplate MainPage}" Route="MainPage" />
</Shell>

I'm getting:

Microsoft.Maui.Controls.Xaml.XamlParseException: 'Position 7:32. DataTemplateExtension: Could not locate type for MainPage.'

My MainPage is located under
Faluf.CodexUI.MAUI/Views/MainPage.xaml + MainPage.xaml.cs (The namespace is set to Faluf.CodexUI.MAUI.Views)
I also set csproj values for PropertyGroup:

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

Steps to Reproduce

  1. Create a new .NET MAUI app
  2. Create a folder Views/
  3. Move MainPage to the new folder, and change namespace accordingly
  4. Open GlobalXmlns.cs and add [assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/maui/global", "<YourNamespace>.Views")]
  5. Open AppShell.xaml and remove prefix colon on the MainPage.

Link to public reproduction project repository

No response

Version with bug

10.0.0-rc.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

net10.0-windows10.0.19041.0

Did you find any workaround?

To use prefix - XmlnsPrefixAttribute works too in the GlobalXmlns.cs, but DataTemplate still needs the prefix.

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    t/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions