The sequence does not contain elements trying to make a ListView in XAML

0

Trying to bin an ObservableCollection in a ListView gives me the following error in the view:
The sequence does not contain any elements.

The view is this:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Alvac.Pages.UserPage"
         Title="Alvac"
         BackgroundColor="{StaticResource BackgroundColor}"
         BindingContext="{Binding Main, Source={StaticResource Locator}}">
<ContentPage.Content>
    <StackLayout
        BindingContext="{Binding Centros}">
        <ListView
            ItemsSource="{Binding Centros}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Frame
                            CornerRadius="20"
                            HasShadow="true"
                            Margin="5">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <StackLayout 
                                        Grid.Column="0"
                                        VerticalOptions="Center">
                                    <Label 
                                        FontAttributes="Bold"
                                        FontSize="Medium" 
                                        Text="{Binding Descripcion}"
                                        TextColor="Black">
                                    </Label>
                                </StackLayout>
                            </Grid>
                        </Frame>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>

    <StackLayout
        VerticalOptions="CenterAndExpand"
        Spacing="10"
        Padding="8">
        <Label 
            Text="Bienvenid@"
            FontSize="18"
            FontAttributes="Bold"
            TextColor="{StaticResource FontColor}"
            VerticalOptions="Center" 
            HorizontalOptions="Center" />
    </StackLayout>
</ContentPage.Content>

And I want to add:

public ObservableCollection<Centro> Centros { get; set; }

Thanks for your help.

    
asked by Dani Paredes 07.05.2018 в 14:20
source

1 answer

0

Already fixed, the error was in the use of two StackLayouts within a single ContentPage.
The mistake he made has nothing to do, but hey, what is he going to do?

Thank you very much for your time.

    
answered by 12.05.2018 / 10:55
source