XamlC error XFC0062: Undeclared xmlns prefix

ThomasB-3258 0 Reputation points
2024-05-27T15:14:18.1133333+00:00

Hi,

I am doing a first test in .NET Maui but can't get this resolved. I keep getting the same compile error on :

Error XFC0062 Undeclared xmlns prefix "mym". MyMauiApp C:\Users\thoma\source\repos\MyMauiApp\MainPage.xaml 17

Output window :
MainPage.xaml(17,35): XamlC error XFC0062: Undeclared xmlns prefix "mym"

<TabbedPage  xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:viewmodel="clr-namespace:MyMauiApp.ViewModels"
             x:Class="MyMauiApp.MainPage"
             x:DataType="viewmodel:MainViewModel">
    <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:mym="clr-namespace:MyMauiApp.Data"
                 x:DataType="mym:CountdownItem"
                 BackgroundImageSource="beach.jpeg" Title="Religion">
        <StackLayout>
            <CollectionView x:Name="religionCollectionView"  ItemsLayout="VerticalList" SelectionMode="Single" SelectionChanged="CollectionView_SelectionChanged" ItemsSource="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:MainViewModel}}, Path=Items} ">
            <CollectionView.ItemTemplate>
                    <DataTemplate x:DataType="{mym:CountdownItem}">
                        <VerticalStackLayout  Padding="5" Margin="5" BackgroundColor="Azure" Opacity="0.8" >
                            <Label Text="{Binding Name}" TextColor="Black" HorizontalOptions="Center"></Label>
                            <Label Text="{Binding StartDate}" TextColor="Black" HorizontalOptions="Center" ></Label>
                        </VerticalStackLayout>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
        </CollectionView>
            <Button x:Name="mybutton" Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:MainViewModel}}, Path=GetAll}"  Text="Click me" Pressed="Button_Pressed" />
        </StackLayout>
    </ContentPage>
    <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             BackgroundImageSource="beach.jpeg" Title="Sports">
        <CollectionView ItemsLayout="VerticalList" SelectionMode="Single" SelectionChanged="CollectionView_SelectionChanged" >
            <CollectionView.ItemsSource>
                <x:Array Type="{x:Type x:String}">
                    <x:String>Paris Olympic games 2024</x:String>
                    <x:String>Euro cup soccer</x:String>
                    <x:String>World cup cycling</x:String>
                </x:Array>
            </CollectionView.ItemsSource>
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <VerticalStackLayout BackgroundColor="red" Padding="5" Margin="5">
                        <Label Text="{Binding .}" TextColor="White" HorizontalOptions="Center"></Label>
                    </VerticalStackLayout>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    </ContentPage>
</TabbedPage>

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,752 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,042 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ThomasB-3258 0 Reputation points
    2024-05-27T17:20:30.5633333+00:00

    Found it.
    Needed to move the namespace of xmlns:mym="clr-namespace:MyMauiApp.Data" to the parent element and remove the x:DataType="mym:CountdownItem" in the ContentPage element.

    0 comments No comments