Hi KaushalyaDharmarathna-0277,
Welcome to our Microsoft Q&A platform!
It is a known issue on Android, and you can follow up the issue here:
https://github.com/xamarin/Xamarin.Forms/issues/9466
Or submit a new issue on github.
A workaround to handle this is using CollectionView.
xaml
<CollectionView x:Name="EmployeeView"
ItemsSource="{Binding Employees}"
SelectionMode="Single"
SelectionChanged="EmployeeView_SelectionChanged"
SelectedItem="{Binding SelectedEmployee, Mode=TwoWay}"
SelectionChangedCommand="{Binding SelectedCommand}">
<CollectionView.ItemTemplate>
<DataTemplate>
<ContentView>
<SwipeView>
<SwipeView.LeftItems>
<SwipeItems>
<SwipeItem Text="Favorite"
BackgroundColor="Blue"/>
<SwipeItem Text="Delete"
BackgroundColor="LightPink" />
</SwipeItems>
</SwipeView.LeftItems>
<StackLayout Orientation="Horizontal"
BackgroundColor="GreenYellow">
<Label Text="{Binding Name}"/>
<Label Text="{Binding Age}"/>
</StackLayout>
</SwipeView>
</ContentView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
viewmodel:
class MainPageViewModel : INotifyPropertyChanged
{
public ICommand SelectedCommand { get; set; }
public List<Employee> Employees { get; set; }
public MainPageViewModel()
{
Employees = new List<Employee>();
for (int i = 0; i < 10; i++)
{
Employees.Add(new Employee() { Name = "Name" + i, Age = "Age" + i });
}
SelectedCommand = new Command(Select);
}
void Select()
{
if (SelectedEmployee != null)
{
Console.WriteLine(SelectedEmployee.Name);
// do something
}
SelectedEmployee = null;
}
Employee selectedEmployee;
public Employee SelectedEmployee
{
get => selectedEmployee;
set
{
selectedEmployee = value;
OnPropertyChanged("SelectedEmployee");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
Regards,
Kyle
If the response is helpful, please click "Accept Answer" and upvote it.
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.