Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Entry keeps getting focused when scrolling listview

      <ListView
                x:Name="ProductsInCartListView"
                HasUnevenRows="True"
                ItemsSource="{Binding Products}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Grid ColumnSpacing="10">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="50" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="100" />
                                </Grid.RowDefinitions>
                                <Button
                                    Grid.Column="0"
                                    BackgroundColor="Transparent"
                                    HorizontalOptions="Center"
                                    Text="x"
                                    VerticalOptions="Center" />

                                <Grid Grid.Column="1">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <Image
                                        Grid.Column="0"
                                        Aspect="AspectFill"
                                        HeightRequest="50"
                                        Source="dog.jpg"
                                        WidthRequest="50" />
                                    <!--  Source="{Binding Product.Photos[0]}"  -->
                                    <StackLayout
                                        x:Name="Product"
                                        Grid.Column="1"
                                        Padding="5,0,5,5">
                                        <Label Text="{Binding Product.Name, Converter={StaticResource SubstringConverter}, ConverterParameter=20}" />
                                        <Label
                                            FontAttributes="Bold"
                                            Text="{Binding Product.Price_EUR, StringFormat=' {0}€'}"
                                            TextColor="Black" />
                                        <Grid HorizontalOptions="EndAndExpand">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="40" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="40" />
                                            </Grid.ColumnDefinitions>
                                            <Button
                                                Grid.Column="0"
                                                BackgroundColor="Transparent"
                                                FontSize="Large"
                                                HorizontalOptions="End"
                                                Text="-"
                                                TextColor="Black"
                                                VerticalOptions="CenterAndExpand" />

                                            <local:SelectableEntry
                                                x:Name="QuantityEntry"
                                                Grid.Column="1"
                                                BackgroundColor="Transparent"
                                                Focused="QuantityEntry_Focused"
                                                HorizontalOptions="End"
                                                HorizontalTextAlignment="Center"
                                                Keyboard="Numeric"
                                                Text="{Binding Quantity}"
                                                TextColor="Black"
                                                VerticalOptions="Center"
                                                WidthRequest="30" />
                                            <Button
                                                Grid.Column="2"
                                                BackgroundColor="Transparent"
                                                FontSize="Medium"
                                                HorizontalOptions="End"
                                                Text="+"
                                                TextColor="Black"
                                                VerticalOptions="Center" />

                                        </Grid>
                                    </StackLayout>
                                </Grid>
                            </Grid>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

        private async void QuantityEntry_Focused(object sender, FocusEventArgs e)
        {
            if(e.IsFocused)
            {
                var a = (Entry)sender;
                await Rg.Plugins.Popup.Services.PopupNavigation.Instance.PushAsync(new QuantityPopupView(a.Text));
            }
        }

As you can see in gif, when I scroll, entry keeps getting focused and then popup keeps opening.
What am I doing wrong or what do I have to do, to prevent this behaviour

Best Answer

  • rozman50rozman50 Member ✭✭
    Accepted Answer

    @LeonLu
    thanks for suggestion.

    Until today, I was using Xamarin 3.4, but today I upgraded to 4.+ (had to install Visual Studio 2019), that fixed my problem quite a bit, but it was still opening unwanted popup pages.

    So what I did, instead of entry I used label, added tap gesture recognizer and when user taps on number, popup opens.

    Code if anyone needs it:

                <Label
            x:Name="QuantityEntry"
            Grid.Column="1"
            BackgroundColor="Transparent"
            HorizontalOptions="End"
            HorizontalTextAlignment="Center"
            Text="1"
            TextColor="Black"
            VerticalOptions="Center"
            WidthRequest="30">
            <Label.GestureRecognizers>
              <TapGestureRecognizer NumberOfTapsRequired="1" Tapped="TapGestureRecognizer_Tapped" />
             </Label.GestureRecognizers>
               </Label>
    

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    This issue was reported as a bug to the github, Here is link.
    https://github.com/xamarin/Xamarin.Forms/issues/1600

    You can replace the ListView to a CollectionView or maybe a ScrollView with a StackLayout.

  • rozman50rozman50 Member ✭✭
    Accepted Answer

    @LeonLu
    thanks for suggestion.

    Until today, I was using Xamarin 3.4, but today I upgraded to 4.+ (had to install Visual Studio 2019), that fixed my problem quite a bit, but it was still opening unwanted popup pages.

    So what I did, instead of entry I used label, added tap gesture recognizer and when user taps on number, popup opens.

    Code if anyone needs it:

                <Label
            x:Name="QuantityEntry"
            Grid.Column="1"
            BackgroundColor="Transparent"
            HorizontalOptions="End"
            HorizontalTextAlignment="Center"
            Text="1"
            TextColor="Black"
            VerticalOptions="Center"
            WidthRequest="30">
            <Label.GestureRecognizers>
              <TapGestureRecognizer NumberOfTapsRequired="1" Tapped="TapGestureRecognizer_Tapped" />
             </Label.GestureRecognizers>
               </Label>
    
  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Ok, thanks for your sharing.

Sign In or Register to comment.