0

I'm trying to render a collectionview inside a stacklayout using Xamarin.forms. But the collectionview isn't showing any data. I'm testing on ios using visual studio for mac.

I'm trying to learn to use the collectionview and Xamarin.Forms basics with ios

I've followed the most basic example from microsoft git repo for xamarin.forms found here: https://github.com/xamarin/xamarin-forms-samples/blob/master/UserInterface/CollectionViewDemos/CollectionViewDemos/Views/Layout/HorizontalListTextPage.xaml

I've copied the simple example to my own project in the Mainpage.xaml file but the collectionview data is only visible if I remove the outer Stacklayout like below

 <?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:demo" x:Class="demo.MainPage">

        <CollectionView ItemsLayout="{x:Static ListItemsLayout.HorizontalList}">
            <CollectionView.ItemsSource>
                <x:Array Type="{x:Type x:String}">
                    <x:String>Baboon</x:String>
                    <x:String>Capuchin Monkey</x:String>
                    <x:String>Blue Monkey</x:String>
                    <x:String>Squirrel Monkey</x:String>
                    <x:String>Golden Lion Tamarin</x:String>
                    <x:String>Howler Monkey</x:String>
                    <x:String>Japanese Macaque</x:String>
                    <x:String>Mandrill</x:String>
                    <x:String>Proboscis Monkey</x:String>
                    <x:String>Red-shanked Douc</x:String>
                    <x:String>Gray-shanked Douc</x:String>
                    <x:String>Golden Snub-nosed Monkey</x:String>
                    <x:String>Black Snub-nosed Monkey</x:String>
                    <x:String>Tonkin Snub-nosed Monkey</x:String>
                    <x:String>Thomas's Langur</x:String>
                    <x:String>Purple-faced Langur</x:String>
                    <x:String>Gelada</x:String>
                </x:Array>
            </CollectionView.ItemsSource>
        </CollectionView>
   </ContentPage>

I have added Forms.SetFlags("CollectionView_Experimental"); to the appdelete

I would expected the data to visible even with the stacklayout present in my mainpage.xaml.

UPDATE If i set the height explicit the collectionview data is visible, but that is not done in any of the examples in this solution but in the example layouts i'm linking to they are not setting the height explicit, that goes for all the examples found here https://github.com/xamarin/xamarin-forms-samples/tree/master/UserInterface/CollectionViewDemos

and if i start example solution they everything is wokring as expected but if i copy the examples over to my own solution i need to set the height explicit.

UPDATE If the MainPage is wrapped in a navigationpage everything is working as expexcted

 MainPage = new NavigationPage(new MainPage()); 

but with the default

MainPage = new MainPage() 

nothing is rendred

  • 1
    you probably need to set the vertical layout options or an explicit height on the Collection – Jason Jun 22 '19 at 22:03
  • 1
    The code you provided is missing a StackLayout, being child of the contentpage – Bruno Caceiro Jun 22 '19 at 23:08
  • @Bruno the example without the stacklayout is what i can get to work, if add a stacklayout as a parent to the colletionview the collectview isn't visible. – Thomas Stern Jun 23 '19 at 07:26
  • @ThomasStern Hi, which is the version of Xamarin.Forms and VisualStudio ,I will check it. – Junior Jiang Jun 24 '19 at 08:37
  • @JuniorJiang-MSFT Latest build I've just tested and found if add the MainPage to as NavigationPage in the App.xaml.cs files everything works as expected like this MainPage = new NavigationPage(new MainPage()); but with the default MainPage = new MainPage() nothing is rendred – Thomas Stern Jun 25 '19 at 09:04
  • @ThomasStern Okey , it occurs in IOS device , not in Android.This is a strange phenomenon. – Junior Jiang Jun 25 '19 at 09:19
  • @JuniorJiang-MSFT Visual studio version 8.1.1 build27 Xamarin.forms 4.0.0.49.7661 – Thomas Stern Jun 25 '19 at 09:24
  • @JuniorJiang-MSFT Tested with emulators and yes agreed it is strange. – Thomas Stern Jun 25 '19 at 09:56
  • @ThomasStern Hi, After some time of verification, this should be a collectionview bug that has been submitted on GitHub. Later you can follow it. https://github.com/xamarin/Xamarin.Forms/issues/6834 – Junior Jiang Jul 11 '19 at 01:07

0 Answers0