locked
xamarin carousel page throws System.ArgumentOutOfRangeException on last page swipe only on Android RRS feed

  • Question

  • User228367 posted

    Xamarin forms carousel page works of UWP but when running on Android the carousel page errors out on the last page when swiped. Instead of stopping an error occurs:

    System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index

    Any help would be much appreciated :-)

    Wednesday, May 25, 2016 11:20 AM

Answers

  • User228367 posted

    I've solved this issue. I've wrapped the "Device.BeginInvoke" around the bound collection of the itemSource property. Executing on the UI thread has solved this issue.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, June 8, 2016 9:47 AM

All replies

  • User179286 posted

    This happens when you swipe by hand? Could you please show us the code/Xaml where create the Pages and what you do in OnPageChanged?

    Wednesday, May 25, 2016 1:15 PM
  • User228367 posted

    Will do, but on OnPageChanged I play a sound effect through the eventtocommand behaviour. Do you think thats whats causing it? Sure - I will paste the code in a bit

    Wednesday, May 25, 2016 1:34 PM
  • User228367 posted
                    <CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
                                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                                 x:Class="Xamarin.UI.Core.View.SituationView"
                                 xmlns:infrustructure="clr-namespace:Xamarin.UI.Core.Infrustructure;assembly=Xamarin.UI.Core"
                                 xmlns:behaviour="clr-namespace:Xamarin.UI.Core.Infrustructure.Behaviour;assembly=Xamarin.UI.Core"
                                 Title="Situations"
                                 ItemsSource="{Binding Situations}"
                                 BackgroundColor="{StaticResource ExcuseMeBackgroundColour}"
                                 x:Name="SituationsCarouselPage">
                      <CarouselPage.Behaviors>
                        <behaviour:EventToCommandBehavior EventName="CurrentPageChanged"
                                                Command="{Binding CurrentPageChangedCommand}"/>
                      </CarouselPage.Behaviors>
                      <CarouselPage.ItemTemplate>
                        <DataTemplate>
                          <ContentPage>
                            <Grid>
                              <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                              </Grid.RowDefinitions>
                              <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                              </Grid.ColumnDefinitions>
                              <ActivityIndicator Grid.Row="1" Grid.Column="1" 
                                                  WidthRequest="{Binding BindingContext.ActivityIndicatorWidth, Source={x:Reference SituationsCarouselPage}}"
                                                  IsRunning="{Binding BindingContext.IsBusy, Source={x:Reference SituationsCarouselPage}}"
                                                  IsVisible="{Binding BindingContext.IsBusy, Source={x:Reference SituationsCarouselPage}}"/>
                              <Frame IsVisible="{Binding BindingContext.IsIdle, Source={x:Reference SituationsCarouselPage}}" 
                                     Grid.Row="1" Grid.Column="1" OutlineColor="Black" HorizontalOptions="Center" VerticalOptions="Center">
                                <StackLayout Orientation="Vertical">
                                  <Label TextColor="{StaticResource ExcuseMeDefaultTextColour}" Text="{Binding Title}" FontSize="30" HorizontalOptions="Center" HorizontalTextAlignment="Center"/>
                                  <Label TextColor="{StaticResource ExcuseMeDefaultTextColour}" HorizontalOptions="Center" HorizontalTextAlignment="Center" Text="{Binding Description}"/>
                                  <Image IsVisible="{Binding IsUnavailable}" Source="{infrustructure:ImageResource Xamarin.UI.Core.Assets.TopSecret.png}"/>
                                  <Image IsVisible="{Binding IsAvailable}" Source="{infrustructure:ImageResource Xamarin.UI.Core.Assets.YoureExcused.png}"/>
                                  <Button Text="Go" IsVisible="{Binding IsAvailable}" 
                                            Command="{Binding BindingContext.NavigateToCategoryCommand, Source={x:Reference SituationsCarouselPage}}" 
                                            CommandParameter="{Binding Title}"
                                            BorderColor="{StaticResource ExcuseMeDefaultButtonBorderColour}"
                                            BackgroundColor="{StaticResource ExcuseMeDefaultButtonColour}"/>
                                  <Label TextColor="{StaticResource ExcuseMeDefaultTextColour}" 
                                         Text="Please log in and purchase this subscription" 
                                         HorizontalOptions="Center" 
                                         HorizontalTextAlignment="Center" 
                                         IsVisible="{Binding IsUnavailable}"/>
                                </StackLayout>
                              </Frame>
                            </Grid>
                          </ContentPage>
                        </DataTemplate>
                      </CarouselPage.ItemTemplate>
                    </CarouselPage>
    
    Wednesday, May 25, 2016 1:40 PM
  • User179286 posted

    Just remove the sound and try

    Wednesday, May 25, 2016 1:40 PM
  • User228367 posted

    I removed the eventtocommand behaviour however the same error still occurs:

    05-25 09:47:28.832 D/Mono ( 1549): DllImport attempting to load: '/system/lib/liblog.so'. 05-25 09:47:28.832 D/Mono ( 1549): DllImport loaded library '/system/lib/liblog.so'. 05-25 09:47:28.832 D/Mono ( 1549): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so'). 05-25 09:47:28.832 D/Mono ( 1549): Searching for 'androidlogprint'. 05-25 09:47:28.832 D/Mono ( 1549): Probing 'androidlogprint'. 05-25 09:47:28.832 D/Mono ( 1549): Found as 'androidlogprint'. 05-25 09:47:29.012 I/MonoDroid( 1549): UNHANDLED EXCEPTION: 05-25 09:47:29.312 I/MonoDroid( 1549): System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. 05-25 09:47:29.312 I/MonoDroid( 1549): Parameter name: index 05-25 09:47:29.312 I/MonoDroid( 1549): at Xamarin.Forms.ListProxy.getItem (Int32 index) [0x0000b] in :0 05-25 09:47:29.322 I/MonoDroid( 1549): at Xamarin.Forms.MultiPage1[T].OnPropertyChanged (System.String propertyName) [0x00092] in <filename unknown>:0 05-25 09:47:29.332 I/MonoDroid( 1549): at Xamarin.Forms.MultiPage1[T].setCurrentPage (Xamarin.Forms.T value) [0x00026] in :0 05-25 09:47:29.332 I/MonoDroid( 1549): at Xamarin.Forms.Platform.Android.CarouselPageAdapter.OnPageSelected (Int32 position) [0x00046] in :0 05-25 09:47:29.342 I/MonoDroid( 1549): at Android.Support.V4.View.ViewPager+IOnPageChangeListenerInvoker.nOnPageSelectedI (IntPtr jnienv, IntPtr nativethis, Int32 position) [0x00009] in :0 05-25 09:47:29.342 I/MonoDroid( 1549): at (wrapper dynamic-method) System.Object:645113bf-d4d1-4935-b86b-c673fe2f093c (intptr,intptr,int) An unhandled exception occured.

    Wednesday, May 25, 2016 1:49 PM
  • User228367 posted

    To give more info the carouselpage is navigated to via a parent navigation page which is set as the MainPage in the App class. This seems to work fine when you hard code the pages in Xaml but when the items are rendered by data template I think this is where the error is triggered. ? I think ?

    Wednesday, May 25, 2016 1:51 PM
  • User228367 posted

    I've solved this issue. I've wrapped the "Device.BeginInvoke" around the bound collection of the itemSource property. Executing on the UI thread has solved this issue.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, June 8, 2016 9:47 AM
  • User82556 posted

    @sachinkanadia I am experiencing this issue too. I filed a bug report at https://bugzilla.xamarin.com/show_bug.cgi?id=43154 before bumping into this. I will update it with a reference to this thread.

    Sunday, August 7, 2016 7:27 PM