When a list item is clicked, the click results of the entry and the label are different.

영훈 정 281 Reputation points
2022-10-12T09:22:57.32+00:00

249616-image.png

<ListView  
                        x:Name="xListview"  
                        Grid.Row="0"  
                        ItemSelected="OnItemSelected"  
                        RowHeight="50">  
                        <ListView.ItemTemplate>  
                            <DataTemplate>  
                                <ViewCell Tapped="OnTappedListItem">  
  
                                    <Grid>  
                                        <Grid.ColumnDefinitions>  
                                            <ColumnDefinition Width="7*" />  
                                            <ColumnDefinition Width="3*" />  
                                        </Grid.ColumnDefinitions>  
  
                                        <!--<Ctrl:CtrlEntry  
                                            Grid.Column="0"  
                                            Margin="20,0,0,0"  
                                            BackgColor="red"  
                                            Completed="OnEditEnd"  
                                            IsReadOnly="True"  
                                            StrokeWidth="0"  
                                            Text="{Binding LabelText}">  
  
                                            <Ctrl:CtrlEntry.GestureRecognizers>  
                                                <TapGestureRecognizer Tapped="OnEntryClicked" />  
                                            </Ctrl:CtrlEntry.GestureRecognizers>  
  
                                        </Ctrl:CtrlEntry>-->  
  
                                        <Label BackgroundColor="Red"  
                                            Grid.Column="0"  
                                            Margin="20,0,0,0"  
                                            Style="{StaticResource LabelStyle}"  
                                            Text="{Binding LabelText}" />  
  
                                        <StackLayout  
                                            Grid.Column="1"  
                                            Margin="0,0,5,0"  
                                            HorizontalOptions="End"  
                                            Orientation="Horizontal"  
                                            Spacing="10"  
                                            VerticalOptions="Center">  
  
                                            <Ctrl:CtrlImageButton  
                                                BackgroundColor="Transparent"  
                                                Clicked="OnModifyClicked"  
                                                HeightRequest="25"  
                                                Source="edit_button.png"  
                                                Tag="false"  
                                                WidthRequest="25" />  
  
                                            <Ctrl:CtrlImageButton  
                                                BackgroundColor="Transparent"  
                                                Clicked="OnDeleteClicked"  
                                                HeightRequest="27"  
                                                Source="btn_delete.png"  
                                                Tag="false"  
                                                WidthRequest="27" />  
  
                                        </StackLayout>  
                                    </Grid>  
  
                                </ViewCell>  
                            </DataTemplate>  
                        </ListView.ItemTemplate>  
                    </ListView>  

249654-8.gif

If a label is placed on a list item, the list item will be clicked even if the label area within the list item area is clicked.

What I want is to put an entry and click in the entry area to make it look like the item list is clicked.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,326 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 39,391 Reputation points Microsoft Vendor
    2022-10-13T08:48:12.773+00:00

    Hello,

    This is due to the fact that the Entry control does not support touch or tap events.

    If your Entry is not read-only, you could use the following code to change the color of list item:

       private void Entry_Focused(object sender, FocusEventArgs e)  
       {  
           var entry = sender as Entry;  
           var p = entry.Parent as Grid;  
           p.BackgroundColor = Color.Gray;  
       }  
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.