Skip to content

CollectionView on Android does not provide height, width, logical children once loaded, works fine on Windows #14364

@KWodarczyk

Description

@KWodarczyk

Description

CollectionView on Android does not provide height, width, logical children once loaded, works fine on Windows

watch on android

image

image

on windows

image

image

code:

    public partial class MainPage : ContentPage
    {

        public MainPage()
        {
            InitializeComponent();
        }

        private void mycollectionview_Loaded(object sender, EventArgs e)
        {

            var h1 = mycollectionview.Height;
            var h2 = mycollectionview.DesiredSize.Height;
            var h3 = mycollectionview.Frame.Height;


            var numberOfVisibleItems = ((IElementController)mycollectionview).LogicalChildren.Count;
        }
    }
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="CollectionViewLoadedBug.MainPage">

    <Grid
        x:Name="myGrid"
        HeightRequest="300"
        WidthRequest="200"

        BackgroundColor="Gray">
        <CollectionView
            Loaded="mycollectionview_Loaded"
            Grid.Row="2"
            x:Name="mycollectionview"
            BackgroundColor="Green"
            VerticalScrollBarVisibility="Never">

            <CollectionView.ItemsLayout>
                <LinearItemsLayout
                    ItemSpacing="0"
                    Orientation="Vertical"
                    SnapPointsAlignment="Center"
                    SnapPointsType="MandatorySingle"/>
            </CollectionView.ItemsLayout>
            <CollectionView.ItemTemplate>
                <DataTemplate >

                    <Frame
                        HasShadow="True"
                        WidthRequest="50"
                        Padding="0"
                        BorderColor="Orange"
                        Background="blue"
                        CornerRadius="5">


                        <Label
                            Text="{Binding}"
                            FontAttributes="Bold"
                            Padding="0"
                            Margin="0"
                            TextColor="Pink"
                            FontSize="18"
                            HorizontalOptions="Center"/>

                    </Frame>

                </DataTemplate>
            </CollectionView.ItemTemplate>

            <CollectionView.ItemsSource>
                <x:Array Type="{x:Type x:Int32}">
                    <x:Int32>1</x:Int32>
                    <x:Int32>2</x:Int32>
                    <x:Int32>3</x:Int32>
                    <x:Int32>4</x:Int32>
                    <x:Int32>5</x:Int32>
                    <x:Int32>6</x:Int32>
                    <x:Int32>7</x:Int32>
                    <x:Int32>8</x:Int32>
                    <x:Int32>9</x:Int32>
                    <x:Int32>10</x:Int32>
                    <x:Int32>11</x:Int32>
                    <x:Int32>12</x:Int32>
                    <x:Int32>13</x:Int32>
                    <x:Int32>14</x:Int32>
                    <x:Int32>15</x:Int32>
                    <x:Int32>16</x:Int32>
                    <x:Int32>17</x:Int32>
                    <x:Int32>18</x:Int32>
                    <x:Int32>19</x:Int32>
                    <x:Int32>20</x:Int32>

                </x:Array>
            </CollectionView.ItemsSource>
        </CollectionView>

    </Grid>

</ContentPage>

Steps to Reproduce

just copy paste code and run

Link to public reproduction project repository

https://github.com/KWodarczyk/MauiBugs/tree/main/CollectionViewLoadedBug

Version with bug

7.0.100

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-collectionviewCollectionView, CarouselView, IndicatorViewarea-layoutStackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenterpartner/syncfusionIssues / PR's with Syncfusion collaborationplatform/androids/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions