0
votes

I want to implement a Carousel view swipe gesture recognizer left or right Swipes.
But ONLY tapped event can be recognized ,gesture events cannot be captured(not firing). What i need is when user swipe left or right according to the swipe event i want to manage dot button opacity accordingly. I saw some nuget packages already there to achieve this.I prefer not to use nuget packages.

I have tried the tapped event,tapped event is firing but not the gesture event

<CarouselView x:Name="CV" ItemsSource="{Binding People}" HeightRequest="200" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" Margin="10" >

                <CarouselView.ItemsLayout>
                    <GridItemsLayout Orientation="Horizontal" SnapPointsAlignment="Center" SnapPointsType="Mandatory"/>
                </CarouselView.ItemsLayout>
                <CarouselView.ItemTemplate>
                    <DataTemplate>
                        <Frame BorderColor="LightGray" CornerRadius="3" HasShadow="False">
                            <Grid>
                                <Grid.GestureRecognizers>
                                    <SwipeGestureRecognizer Direction="Left" Swiped="SwipeGestureRecognizer_OnSwiped" />
                                    <SwipeGestureRecognizer Direction="Right" Swiped="SwipeGestureRecognizer_OnSwiped"/>
                                    <SwipeGestureRecognizer Direction="Up" Swiped="SwipeGestureRecognizer_OnSwiped" />
                                    <SwipeGestureRecognizer Direction="Down" Swiped="SwipeGestureRecognizer_OnSwiped"/>
                                </Grid.GestureRecognizers>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="75"/>
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <Image Grid.Column="0" Grid.Row="0" Source="person" VerticalOptions="Start"/>
                                <StackLayout Grid.Column="1" Grid.Row="1" HorizontalOptions="EndAndExpand" VerticalOptions="EndAndExpand">
                                    <Label Text="{Binding}" FontSize="24" HorizontalOptions="EndAndExpand"/>
                                    <Label Text="Company Address" HorizontalOptions="EndAndExpand"/>
                                    <Label Text="City, State" HorizontalOptions="EndAndExpand"/>
                                </StackLayout>
                            </Grid>
                        </Frame>
                    </DataTemplate>
                </CarouselView.ItemTemplate>
            </CarouselView>
1
the Carosuel should natively handle swipe gestures - why are you trying do create your own?Jason
in which action i should handle.Could you share the code for it?Black

1 Answers

0
votes

Yes,CarouselView have GestureRecognizers ,for example,

<CarouselView>
            <CarouselView.GestureRecognizers>
                <SwipeGestureRecognizer  Swiped="OnSwiped"  />                   
            </CarouselView.GestureRecognizers>
 </CarouselView>

method OnSwiped

private void OnSwiped(object sender, SwipedEventArgs e)
    {
        if (e.Direction == (e.Direction & SwipeDirection.Left))
        {

        }
    }