Dan
Dan

Reputation: 1110

Disable selecting Items in ListView

For a Social Networking app I am working on I am trying to display comments with a ListView but I do not want it to be highlighted when clicked.

I tried using

`((ListView)sender).SelectedItem = null;` in a selected event but that still shows it being selected for a second. I need it to never show.

I also tried setting the List View to

IsEnabled="False"

also tried putting it in the View Cell but that causes the buttons and click events to not work.

Upvotes: 1

Views: 3599

Answers (2)

Dan
Dan

Reputation: 1110

Android:

I created a custom renderer for ListView and set

Control.SetSelector(Android.Resource.Color.Transparent);

iOS:

I created a custom ViewCell renderer and set

cell.SelectionStyle = UITableViewCellSelectionStyle.None;

References:

Android: Xamarin.Forms untappable ListView (remove selection ripple effect)

iOS: https://montemagno.com/adding-a-disclosure-indicator-accessory-to/

Upvotes: 5

Sajeetharan
Sajeetharan

Reputation: 222720

You can try something like this,

myListView.ItemTapped += (object sender, ItemTappedEventArgs e) => {    
   if (e.Item == null) return;     
    ((ListView)sender).SelectedItem = null; 
 }; 

Upvotes: 2

Related Questions