Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,888 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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>
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.