Home > other >  Repeating Error: XLS0305: Closing tag for element '<CollectionView>' was not found e
Repeating Error: XLS0305: Closing tag for element '<CollectionView>' was not found e

Time:12-23

I downloaded Visual Studio 2022 for Mac and am learning .NET Maui

I have been following this basic tutorial Build .NET MAUI UI with XAML [4 of 8] | .NET MAUI for Beginners

Adding things such as Buttons and Entry have been fine and rendered properly but when I get to adding <CollectionView>, I get repeating errors saying

Error: XLS0112: Expected '>'. (MauiApp2) IntelliSense

Error: XLS0305: Closing tag for element '<CollectionView>' was not found. (MauiApp2) IntelliSense

I am getting the same error for elements that are inside the <CollectionView> as well such as <x:Array> and <x:String>

Here is my code: MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp2.MainPage">

    <Grid RowDefinitions="100, Auto, *"
          ColumnDefinitions=".75*, .25*"
          Padding="10"
          RowSpacing="10"
          ColumnSpacing="10">

        <Image Grid.ColumnSpan="2"
               Source="dotnet_bot.png"
               BackgroundColor="Orange"/>

        <Entry Placeholder="Enter Task"
               Grid.Row="1"/>

        <Button Text="Add"
                Grid.Row="1"
                Grid.Column="1" />

        <CollectionView Grid.Row="2" Grid.Column="2">
           <CollectionView.ItemsSource>
                <x:Array Type="{x:Type x:String}">
                    <x:String>apples</x:String>
                    <x:String>grapes</x:String>
                    <x:String>oranges</x:String>
                </x:Array>

            </CollectionView.ItemsSource>

        </CollectionView>

    </Grid>

</ContentPage>

I have

  • restarted Visual Studio multiple times
  • restarted my computer
  • rewritten my code
  • checked for VS updates
  • used a different simulator
  • cleaned solution
  • rebuilt solution
  • cleaned then rebuilt solution

but I can't seem to figure out the problem

CodePudding user response:

Not sure why it gives that specific error, but it might go away once you add this essential property of CollectionView: the ItemTemplate:

  <CollectionView.ItemTemplate>
    <DataTemplate>
      <Label Text="Test" />
    </DataTemplate>
  <CollectionView.ItemTemplate>

Without that, a CollectionView is not valid, cannot display anything.

Perhaps this confuses Intellisense. (Though I haven't thought of any reason why it would give the error it does. It should complain about the missing ItemTemplate.)

CodePudding user response:

I copied your code to my app and did a test on my android emulator, but it works well on my side.

You try to delete the bin folders and the obj folders and rebuild it. If it doesn’t work,try to restart the Visual Studio.

Or you can create a new demo and copy your code to this new demo and try again.

  • Related