Developer00
Developer00

Reputation: 103

Xamarin ListView not showing all items

I'm struggling to make this listview display all items but it doesn't load them from the 7th. What it does is basically it load in an arrayList some products, then it transfers them to a string arraylist and with itemsource it loads them into the listview. I know for sure that the problem is not the arrayList but I can't figure out what is the issue then. Edit: it loads all the frames but it doesn't put inside the background nor the labels.

Here's my xaml code:

<ContentPage.Content>
            <StackLayout>
                <ListView x:Name="listView" HasUnevenRows="true" IsPullToRefreshEnabled="False">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <Frame Padding="2" CornerRadius="5" BackgroundColor="#FFBB00" Margin="20,20,20,20">
                                    <Frame CornerRadius="5" HeightRequest="200" Padding="0" BackgroundColor="Black" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                                        <AbsoluteLayout>
                                            <Image Source="sfondo.jpg" Aspect="Fill"  Opacity="0.6" HeightRequest="200">
                                            </Image>
                                            <Frame AbsoluteLayout.LayoutBounds="0.5,0.5,-1,-1" AbsoluteLayout.LayoutFlags="PositionProportional" HorizontalOptions="Center" VerticalOptions="Center" Padding="5" BackgroundColor="#FFBB00" CornerRadius="10" BorderColor="Black">
                                                <Label Text="{Binding}" FontSize="18" FontAttributes="Bold" FontFamily="Open Sans" TextColor="Black" />
                                            </Frame>
                                        </AbsoluteLayout>
                                    </Frame>
                                </Frame>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </ContentPage.Content>

And here's my c# code:

public partial class ProductsList : ContentPage
    {
        ArrayList lista;
        ListaProdotti lp;

        public ProductsList()
        {
            InitializeComponent();
            BindingContext = this;
            lp = new ListaProdotti();
            lista = new ArrayList();
            foreach (Prodotto prod in lp.getLista())
            {
                lista.Add(prod.getNome());
            }

            createListView();
        }

        public void createListView() { 

            ListView listView = (ListView)FindByName("listView");
            listView.ItemsSource = lista;
        }
    }

Upvotes: 0

Views: 1173

Answers (1)

Lucas Zhang
Lucas Zhang

Reputation: 18861

Cause: You set the ViewCell as a frame , but frame will not fit the size of its child elements.

Solution: If you want to let the label in the center of the frame , you can put the frame in a Grid.

<ViewCell>
    <Grid>
      <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>

      <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>

      <Frame Grid.Row="0" Grid.Column="0" Padding="2" CornerRadius="5" BackgroundColor="#FFBB00" Margin="20,20,20,20">
         <Frame CornerRadius="5" HeightRequest="200" Padding="0" BackgroundColor="Black" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
             <StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
                  <Frame  HorizontalOptions="Center" VerticalOptions="Center" Padding="5" BackgroundColor="#FFBB00" CornerRadius="10" BorderColor="Black">
                     <Label Text="{Binding xxx}" FontSize="18" FontAttributes="Bold" FontFamily="Open Sans" TextColor="Black" />
                  </Frame>
             </StackLayout>
         </Frame>
       </Frame>
    </Grid>
</ViewCell>

Upvotes: 1

Related Questions