0
votes

I have setup list view inside carousel view but how can archive set list view selected item is null, Now when I tap any item carousel view inside list view items it show's default color but we need to remove that color. Please suggest any idea. Thanks in advance.

Sample Code :

 <cv:CarouselView VerticalOptions = "FillAndExpand" HorizontalOptions = "FillAndExpand" Position = "{Binding DishCategory}" ItemSelected = "OnSwipeDishesHandler" ItemsSource = "{Binding RestaurantDishesList}" x:Name = "RestaurantDishesList">
                    <cv:CarouselView.HeightRequest>
                        <OnIdiom x:TypeArguments ="x:Double" Phone ="230" Tablet ="630"/>
                    </cv:CarouselView.HeightRequest>                  
                    <cv:CarouselView.ItemTemplate>
                        <DataTemplate>
                            <StackLayout Padding = "10,5,10,5" Orientation = "Vertical">
                                <ListView x:Name="RestaurantMenuListView" BackgroundColor="Transparent" ItemsSource="{Binding CategoryWiseDishes}" HasUnevenRows="true" SeparatorColor="#eeeeee">
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <ViewCell>
                                                <StackLayout Padding="7">
                                                    <Grid Padding="2">
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition Width="*"/>
                                                            <ColumnDefinition Width="Auto"/>
                                                        </Grid.ColumnDefinitions>
                                                        <StackLayout Grid.Column="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                                                            <StackLayout.GestureRecognizers>
                                                                <TapGestureRecognizer Tapped="OnMenuItemSelected"/>
                                                            </StackLayout.GestureRecognizers>
                                                            <Label Text="{Binding Name}" TextColor="Black">
                                                                <Label.FontSize>
                                                                    <OnIdiom x:TypeArguments ="x:Double" Phone ="15" Tablet ="20"/>
                                                                </Label.FontSize>
                                                            </Label>
                                                            <Label Text="{Binding Description}" TextColor="#323232">
                                                                <Label.FontSize>
                                                                    <OnIdiom x:TypeArguments ="x:Double" Phone ="11" Tablet ="16"/>
                                                                </Label.FontSize>
                                                            </Label>
                                                            <StackLayout Orientation="Horizontal">
                                                                <Label Text="£" TextColor="Black">
                                                                    <Label.FontSize>
                                                                        <OnIdiom x:TypeArguments ="x:Double" Phone ="14" Tablet ="19"/>
                                                                    </Label.FontSize>
                                                                </Label>
                                                                <Label Text="{Binding Cost}" TextColor="Black">
                                                                    <Label.FontSize>
                                                                        <OnIdiom x:TypeArguments ="x:Double" Phone ="14" Tablet ="19"/>
                                                                    </Label.FontSize>
                                                                </Label>
                                                            </StackLayout>
                                                        </StackLayout>
                                                        <StackLayout Grid.Column="1" Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                                                            <Image Source="minus.png">
                                                                <Image.WidthRequest>
                                                                    <OnIdiom x:TypeArguments ="x:Double" Phone ="25" Tablet ="35"/>
                                                                </Image.WidthRequest>
                                                                <Image.HeightRequest>
                                                                    <OnIdiom x:TypeArguments ="x:Double" Phone ="25" Tablet ="35"/>
                                                                </Image.HeightRequest>
                                                                <Image.GestureRecognizers>
                                                                    <TapGestureRecognizer Tapped="RemoveItemBtnClicked"/>
                                                                </Image.GestureRecognizers>
                                                            </Image>
                                                          <Label Text="{Binding TotalQuantity}" HorizontalOptions="Center" VerticalOptions="Center" TextColor="Black">
                                                            <Label.FontSize>
                                                              <OnIdiom x:TypeArguments="x:Double">
                                                                <OnIdiom.Phone>
                                                                  <OnPlatform x:TypeArguments="x:Double" iOS="13" Android="13" WinPhone="13" />
                                                                </OnIdiom.Phone>
                                                                <OnIdiom.Tablet>
                                                                  <OnPlatform x:TypeArguments="x:Double" iOS="15" Android="15" WinPhone="15" />
                                                                </OnIdiom.Tablet>
                                                              </OnIdiom>
                                                            </Label.FontSize>
                                                          </Label>
                                                            <Image Source="add.png">
                                                                <Image.WidthRequest>
                                                                    <OnIdiom x:TypeArguments ="x:Double" Phone ="25" Tablet ="35"/>
                                                                </Image.WidthRequest>
                                                                <Image.HeightRequest>
                                                                    <OnIdiom x:TypeArguments ="x:Double" Phone ="25" Tablet ="35"/>
                                                                </Image.HeightRequest>
                                                                <Image.GestureRecognizers>
                                                                    <TapGestureRecognizer Tapped="AddItemBtnClicked"/>
                                                                </Image.GestureRecognizers>
                                                            </Image>
                                                        </StackLayout>
                                                    </Grid>
                                                </StackLayout>
                                            </ViewCell>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                            </StackLayout>
                        </DataTemplate>
                    </cv:CarouselView.ItemTemplate>
                </cv:CarouselView>    

When I click on total quantity label it show's default color in row. Need to remove that color.

2
What have you tried so far? What isn't working?spaceplane
Thanks for spend time with my question. I have try to set selected event in list view item is null but carousel view inside list view is not detected in xaml.cs file. Then how can I setup selected event is null for carousel view inside list viewDeepak
please show your xamlYuri S
Hi yuri, I have updated my question with sample code. Can you please look that once.Deepak

2 Answers

1
votes

In your xaml file....

<ListView x:Name="RestaurantMenuListView" BackgroundColor="Transparent" ItemsSource="{Binding CategoryWiseDishes}" HasUnevenRows="true" SeparatorColor="#eeeeee" ItemTapped="OnItemTapped">

Then in your xaml.cs file....

public void OnItemTapped(object sender, ItemTappedEventArgs e)
    {
        ((ListView)sender).SelectedItem = null;
    }
0
votes

If you use MVVM instead of Code Behind visit this Tutorial.

You should use two Bindings or go to this Tutorial.

http://www.geojorgx.com/programacion/collection-view-and-the-horrible-itemselectednull/

public ICommand SelectionCommand => new Command(ItemSelected);

        private async void ItemSelected()

        {

            if (Selection != null)

            {

                var persondetaildata = Selection.Name;

                await Shell.Current.GoToAsync($"//DetailPage?persondetaildata={persondetaildata}");

                Selection = null;

            }

        }