I have a list view. On Tapping the selected row, how do I deselect? If I select a different row which is not selected, it must select it. How do I do this? Thanks
<ListView x:Name="DimensionListView" HasUnevenRows="True" ItemTapped="OnItemSelected" SeparatorVisibility="Default" VerticalOptions="FillAndExpand" >
Do you mean you want to deselect the item which is selected when you click it again?
If yes,you could check below:
<ListView x:Name="DimensionListView" HasUnevenRows="True" ItemTapped="OnItemSelected" SeparatorVisibility="Default" VerticalOptions="FillAndExpand" >
in the page.xaml.cs:
int preIndex = -1;
private void OnItemSelected(object sender, ItemTappedEventArgs e)
{
if (preIndex == e.ItemIndex)
{
DimensionListView.SelectedItem = null;
preIndex = -1;
}
else
{
preIndex = e.ItemIndex;
}
}
<ListView x:Name="DimensionListView" HasUnevenRows="True" ItemTapped="OnItemSelected" SeparatorVisibility="Default" VerticalOptions="FillAndExpand" >
Your on ItemSelected handler:
private void OnItemSelected(object sender, ItemTappedEventArgs e)
{
if (DimensionListView.SelectedItem == null)
{
return;
}
DimensionListView.SelectedItem = null;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.