Nested SfListview AutoFitMode="Height" not working, Please help.

<?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:viewmodel="clr-namespace:ZUMOBAPP.ViewModels"
             xmlns:helper="clr-namespace:ZUMOBAPP.Helpers" Title="Class Attendance"
             xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms"
             xmlns:dataSource="clr-namespace:Syncfusion.DataSource;assembly=Syncfusion.DataSource.Portable"
             x:Class="ZUMOBAPP.Views.Faculty.Attendance">

    <ContentPage.BindingContext>
        <viewmodel:AttendanceViewModel />
    </ContentPage.BindingContext>

    <ContentPage.Resources>
        <ResourceDictionary>
            <helper:GroupHeaderConverter x:Key="TemplateConverter"/>
            <helper:IndexToColorConverter x:Key="IndexToColorConverter"/>
        </ResourceDictionary>
    </ContentPage.Resources>

    <ContentPage.Content>
        <Grid RowSpacing="0" ColumnSpacing="0" Padding="0" Margin="0">
            <syncfusion:SfListView x:Name="listViewMain" AutoFitMode="Height" AllowGroupExpandCollapse="True" SelectionMode="None" 
                                   GroupHeaderSize="50" SelectionBackgroundColor="White" ItemsSource="{Binding AttendanceInfo}">

                <syncfusion:SfListView.DataSource>
                    <dataSource:DataSource>
                        <dataSource:DataSource.GroupDescriptors>
                            <dataSource:GroupDescriptor PropertyName="DayOfWeekWithDate" />
                        </dataSource:DataSource.GroupDescriptors>
                    </dataSource:DataSource>
                </syncfusion:SfListView.DataSource>

                <syncfusion:SfListView.GroupHeaderTemplate>
                    <DataTemplate>
                        <StackLayout Orientation="Horizontal" x:Name="stackGroupHeader" Margin="0,0,0,2" 
                                             BackgroundColor="{Binding Level,Converter={StaticResource TemplateConverter}}"
                                             Padding="{Binding Level,Converter={StaticResource TemplateConverter}}">
                            <Label Text="{Binding Key}" FontSize="22"
                                           FontAttributes="Bold" Margin="3"
                                           VerticalOptions="Center" HorizontalOptions="Start">
                                <Label.FontSize>
                                    <OnPlatform x:TypeArguments="x:Double">
                                        <OnPlatform.WinPhone>
                                            <OnIdiom x:TypeArguments="x:Double" Phone="18" Tablet="22" />
                                        </OnPlatform.WinPhone>
                                        <OnPlatform.Android>
                                            <OnIdiom x:TypeArguments="x:Double"
                                                    Phone="18"
                                                    Tablet="22" />
                                        </OnPlatform.Android>
                                        <OnPlatform.iOS>
                                            <OnIdiom x:TypeArguments="x:Double"
                                                    Phone="18"
                                                    Tablet="22" />
                                        </OnPlatform.iOS>
                                    </OnPlatform>
                                </Label.FontSize>
                            </Label>
                            <!--<Image Source="plus" VerticalOptions="Center" HorizontalOptions="End" Margin="0,0,10,0"></Image>-->
                        </StackLayout>
                    </DataTemplate>
                </syncfusion:SfListView.GroupHeaderTemplate>

                <syncfusion:SfListView.ItemTemplate>
                    <DataTemplate>
                        <Grid RowSpacing="0" ColumnSpacing="0" Padding="0" Margin="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">

                            
                            
                            <syncfusion:SfListView ItemTapped="listViewInner_ItemTapped" x:Name="listViewInner" ItemSize="110" ItemsSource="{Binding Listcsviewmodel}" SelectionBackgroundColor="White">
                                <syncfusion:SfListView.ItemTemplate>
                                    <DataTemplate>
                                        <ViewCell>
                                            <ViewCell.View>
                                                <StackLayout HeightRequest="100">
                                                    <Label Text="hello"></Label>
                                                    <Label Text="hello1"></Label>
                                                    <Label Text="hello2"></Label>
                                                    <Label Text="hello3"></Label>
                                                    <Label Text="hello4"></Label>
                                                    <Label Text="hello5"></Label>
                                                </StackLayout>
                                            </ViewCell.View>
                                        </ViewCell>
                                    </DataTemplate>
                                </syncfusion:SfListView.ItemTemplate>
                            </syncfusion:SfListView>






                        </Grid>
                    </DataTemplate>
                </syncfusion:SfListView.ItemTemplate>
            </syncfusion:SfListView>
        </Grid>
    </ContentPage.Content>
</ContentPage>

8 Replies

SA Sadhik replied to Sadhik May 29, 2018 05:33 AM UTC

<?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:viewmodel="clr-namespace:ZUMOBAPP.ViewModels"
             xmlns:helper="clr-namespace:ZUMOBAPP.Helpers" Title="Class Attendance"
             xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms"
             xmlns:dataSource="clr-namespace:Syncfusion.DataSource;assembly=Syncfusion.DataSource.Portable"
             x:Class="ZUMOBAPP.Views.Faculty.Attendance">

    <ContentPage.BindingContext>
        <viewmodel:AttendanceViewModel />
    </ContentPage.BindingContext>

    <ContentPage.Resources>
        <ResourceDictionary>
            <helper:GroupHeaderConverter x:Key="TemplateConverter"/>
            <helper:IndexToColorConverter x:Key="IndexToColorConverter"/>
        </ResourceDictionary>
    </ContentPage.Resources>

    <ContentPage.Content>
        <Grid RowSpacing="0" ColumnSpacing="0" Padding="0" Margin="0">
            <syncfusion:SfListView x:Name="listViewMain" AutoFitMode="Height" AllowGroupExpandCollapse="True" SelectionMode="None" 
                                   GroupHeaderSize="50" SelectionBackgroundColor="White" ItemsSource="{Binding AttendanceInfo}">

                <syncfusion:SfListView.DataSource>
                    <dataSource:DataSource>
                        <dataSource:DataSource.GroupDescriptors>
                            <dataSource:GroupDescriptor PropertyName="DayOfWeekWithDate" />
                        </dataSource:DataSource.GroupDescriptors>
                    </dataSource:DataSource>
                </syncfusion:SfListView.DataSource>

                <syncfusion:SfListView.GroupHeaderTemplate>
                    <DataTemplate>
                        <StackLayout Orientation="Horizontal" x:Name="stackGroupHeader" Margin="0,0,0,2" 
                                             BackgroundColor="{Binding Level,Converter={StaticResource TemplateConverter}}"
                                             Padding="{Binding Level,Converter={StaticResource TemplateConverter}}">
                            <Label Text="{Binding Key}" FontSize="22"
                                           FontAttributes="Bold" Margin="3"
                                           VerticalOptions="Center" HorizontalOptions="Start">
                                <Label.FontSize>
                                    <OnPlatform x:TypeArguments="x:Double">
                                        <OnPlatform.WinPhone>
                                            <OnIdiom x:TypeArguments="x:Double" Phone="18" Tablet="22" />
                                        </OnPlatform.WinPhone>
                                        <OnPlatform.Android>
                                            <OnIdiom x:TypeArguments="x:Double"
                                                    Phone="18"
                                                    Tablet="22" />
                                        </OnPlatform.Android>
                                        <OnPlatform.iOS>
                                            <OnIdiom x:TypeArguments="x:Double"
                                                    Phone="18"
                                                    Tablet="22" />
                                        </OnPlatform.iOS>
                                    </OnPlatform>
                                </Label.FontSize>
                            </Label>
                            <!--<Image Source="plus" VerticalOptions="Center" HorizontalOptions="End" Margin="0,0,10,0"></Image>-->
                        </StackLayout>
                    </DataTemplate>
                </syncfusion:SfListView.GroupHeaderTemplate>

                <syncfusion:SfListView.ItemTemplate>
                    <DataTemplate>
                        <Grid RowSpacing="0" ColumnSpacing="0" Padding="0" Margin="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">

                            
                            
                            <syncfusion:SfListView ItemTapped="listViewInner_ItemTapped" x:Name="listViewInner" ItemSize="110" ItemsSource="{Binding Listcsviewmodel}" SelectionBackgroundColor="White">
                                <syncfusion:SfListView.ItemTemplate>
                                    <DataTemplate>
                                        <ViewCell>
                                            <ViewCell.View>
                                                <StackLayout HeightRequest="100">
                                                    <Label Text="hello"></Label>
                                                    <Label Text="hello1"></Label>
                                                    <Label Text="hello2"></Label>
                                                    <Label Text="hello3"></Label>
                                                    <Label Text="hello4"></Label>
                                                    <Label Text="hello5"></Label>
                                                </StackLayout>
                                            </ViewCell.View>
                                        </ViewCell>
                                    </DataTemplate>
                                </syncfusion:SfListView.ItemTemplate>
                            </syncfusion:SfListView>






                        </Grid>
                    </DataTemplate>
                </syncfusion:SfListView.ItemTemplate>
            </syncfusion:SfListView>
        </Grid>
    </ContentPage.Content>
</ContentPage>

Without specifying the height of the inner SfListView the list wont appear, but the list item is having different no of rows so empty space is coming below the content. Please find the attached screenshots,

Attachment: Screenshots_2eba7321.zip


MK Muthu Kumaran Gnanavinayagam Syncfusion Team May 30, 2018 04:03 AM UTC

Hi Sadhik, 
 
We have checked the reported requirement and referred the attached Template from our side. We would like to let you know that the ItemSize (both height and width) for each items in View will be got from the respective renderers by passing the desired content(underlying data) as View and layout the measured size as ListViewItem based on ItemIndex in SfListView. We regret to inform you that while measuring the size(both height and width) for the nested SfListView(inner list as one ItemData) as content in respective renderers, the size is measured as 1 because the SfListView content does not contain any data and it uses ScrollView as child. So, both height and width is returned as 1 from the respective renderers and this is the actual behavior. We have also ensured with Xamarin ListView too by using the same scenario with HasUnEvenRows as “true” and behaves as mentioned. To overcome the issue, either you need to define the HeightRequest for each inner SfListView or set the inner SfListView’s AutoFitMode as “Height” and define the ItemSize for outer SfListView. In our sample we have added IEnumerable<string> items in SfListView with the provided template and checked whether the items are loaded in the View. For your reference, we have attached the tested sample and you can download it from the below link.  
  
 
Regards, 
G.Muthu kumaran. 



SA Sadhik May 30, 2018 07:25 AM UTC

Thank you for clarifying as I thought there was some issue in my xaml. 
I resolved it by defining the HeightRequest (according to the number of rows) for each inner SfListView as you suggested.

Really appreciate your support. Keep up the good work.


MK Muthu Kumaran Gnanavinayagam Syncfusion Team May 30, 2018 07:34 AM UTC

Hi Sadhik, 
 
Thanks for your valuable response. 
 
Regards, 
G.Muthu kumaran. 



RE Reza November 15, 2019 04:45 PM UTC

Having the same issues with a Listview placed inside and Accordion Item Content. There is lot of blank space below the Listview Items. I have tried specifying the Listviews Autofitmore="Height" as well as setting the Height request for the Listview Stacklayout items but no success. Can you post what was done to solve the OP's question please? The link above to the sample project is not downloadable.


GP Gnana Priya Namasivayam Syncfusion Team November 18, 2019 12:59 PM UTC

Hi Reza,


We have updated the response for the reported query under Forum #149119 which has been created under your account. Please follow-up with the respected forum #149119 for further updates.

Regards,
Gnana Priya N



FL Floyd Lozano December 8, 2019 06:35 AM UTC

I tried to download that sample you provided as an answer but could not.  Can you make it publicly available please?



GP Gnana Priya Namasivayam Syncfusion Team December 9, 2019 08:36 AM UTC

Hi Floyd, 
 
We have re-attached the sample for your reference, please find the sample from following link. 
 
Sample: ListViewSample 
 
Please let us know if you need any further assistance. 
 
Regards, 
Gnana Priya N 


Loader.
Up arrow icon