locked
ListView not working in CarouselView RRS feed

  • Question

  • User363743 posted

    Greetings!

    I am trying to include a ListView as an element in a static array in a CarouselView. This is the XAML code in my sandbox project:

    <?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:XamarinSandbox"
                 xmlns:cv="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
                 x:Class="XamarinSandbox.MainPage">
    
        <cv:CarouselViewControl x:Name="carousel" 
                                InterPageSpacing="10"
                                Orientation="Horizontal"
                                Position="{Binding Position}"
                                ShowArrows="True"
                                ShowIndicators="True"
                                HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
    
            <cv:CarouselViewControl.ItemsSource>
                <x:Array Type="{x:Type View}">
    
                    <Label Text="{Binding LabelText}" BackgroundColor="CadetBlue" FontSize="Large"
                           HorizontalTextAlignment="Center" HorizontalOptions="CenterAndExpand" VerticalTextAlignment="Center" VerticalOptions="CenterAndExpand" />
    
                    <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                        <Label Text="{Binding ProgramModeInstructionsText}" FontSize="Large"
                               HorizontalTextAlignment="Center" HorizontalOptions="CenterAndExpand" VerticalTextAlignment="Center" VerticalOptions="CenterAndExpand" />
    
                        <ListView ItemsSource="{Binding ItemsSource}" SelectedItem="{Binding SelectedItem}"
                                  HasUnevenRows="True" HeightRequest="200" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                   <TextCell Text="REMOVE THIS LINE AND THE CODE COMPILES" />
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
    
                        <Label Text="{Binding SelectedProgramModeDescription}" FontSize="Large"
                               HorizontalTextAlignment="Center" HorizontalOptions="CenterAndExpand" VerticalTextAlignment="Center" VerticalOptions="CenterAndExpand" />
                    </StackLayout>
    
                </x:Array>
            </cv:CarouselViewControl.ItemsSource>
    
        </cv:CarouselViewControl>
    
    </ContentPage>
    

    With this XAML definition, I receive the following compilation error: Value cannot be null. Parameter name: fieldType (I am using [assembly: XamlCompilation(XamlCompilationOptions.Compile)])

    I have been removing lines and compiling to see where the error lays. If I remove the TextCell element, then the XAML definition compiles without error.

    I am at a loss to understand what is going on. This is a basic sandbox project with nothing else in it save the view model that responds to this view. However, I have removed every binding to make the example as simple as possible. The code behind class has had no code added to it.

    Does anyone have any ideas why this is not compiling? Using Xamarin version 2.5.0.280555. Thank you.

    Wednesday, April 4, 2018 11:15 PM

Answers

  • User198446 posted

    Hi You can try this plugin

    https://github.com/AndreiMisiukevich/CardView Just add ListViewRenderer like https://github.com/AndreiMisiukevich/CardView/blob/master/PanCardView.Droid/ParentScrollViewRenderer.cs

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, April 5, 2018 4:21 PM

All replies

  • User277514 posted

    I think you have to create a different content page having listview and then add that contentpage to carousel page. It will make your UI separate and responsive.

    Thursday, April 5, 2018 5:56 AM
  • User198446 posted

    Hi You can try this plugin

    https://github.com/AndreiMisiukevich/CardView Just add ListViewRenderer like https://github.com/AndreiMisiukevich/CardView/blob/master/PanCardView.Droid/ParentScrollViewRenderer.cs

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, April 5, 2018 4:21 PM
  • User363743 posted

    @AndreiMisiukevich_ , I have downloaded the PanCardViewSample sample solution. On both my physical Android device and in an emulator, the program crashes upon launch with the following message:

    Unfortunately, PanCardViewSample has stopped

    I am using the latest versions of Visual Studio 2017 Community.

    Friday, April 6, 2018 10:41 PM
  • User363743 posted

    @VIVEKNEGI, let me give that a try.

    Friday, April 6, 2018 10:49 PM
  • User198446 posted

    @RayGoudie do you use latest android build tools? http://prntscr.com/j22swg

    Saturday, April 7, 2018 8:46 AM
  • User363743 posted

    @AndreiMisiukevich_, I just tried creating a brand-new Xamarin app from scratch, and changed nothing in the projects. If I try to run the app on either an emulator or my Android device, I receive the error message:

    Unfortunately, XamarinSandbox.Android has stopped.

    My apologies for implying that your library might have been faulty.

    This message seems to have started after upgrading to Visual Studio 2017 Community Edition version 15.6.5. The Xamarin template generated code for Xamarin Forms 2.5.1.444934.

    Is anybody else experiencing the same issue with the latest version of VS?

    Saturday, April 7, 2018 5:20 PM
  • User363743 posted

    Yes, I am using the latest build tools.

    @AndreiMisiukevich_ said: @RayGoudie do you use latest android build tools? http://prntscr.com/j22swg

    Saturday, April 7, 2018 5:28 PM
  • User198446 posted

    @RayGoudie I'm sad to read this.. but I can't help, because I use VS for Mac..

    Saturday, April 7, 2018 5:53 PM
  • User363743 posted

    Thank you, @AndreiMisiukevich_ . Your library enabled me to continue with my project.

    Friday, April 13, 2018 10:26 PM
  • User363743 posted

    For the record, my issue with not being able to run any Android projects was due to update 15.6.5 of Visual Studio. A few days after this update, Microsoft released update 15.6.6 which corrected an obvious regression.

    Friday, April 13, 2018 10:27 PM
  • User60333 posted

    I have the same problem

    Wednesday, January 2, 2019 9:10 PM
  • User294116 posted

    Ypu have to put your list view in a separate content view and then it works

    Tuesday, June 11, 2019 2:22 PM