1

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.

Dan
  • 1,100
  • 2
  • 13
  • 36
  • @mjwills Edited some detail in – Dan Feb 11 '18 at 05:59
  • did you checked similar post [here](https://stackoverflow.com/questions/4343793/how-to-disable-highlighting-on-listbox-but-keep-selection) – rahulaga-msft Feb 11 '18 at 06:58
  • @RahulAgarwal That didn't help much, I used (iOS) https://montemagno.com/adding-a-disclosure-indicator-accessory-to/ and (Android) https://stackoverflow.com/questions/35586243/xamarin-forms-untappable-listview-remove-selection-ripple-effect/36225591#36225591 which worked perfectly – Dan Feb 11 '18 at 07:05
  • If you have solved your problem make your own answer, add the details of why it worked for you and mark your answer as correct – TheGeneral Feb 11 '18 at 07:33

2 Answers2

5

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/

zx485
  • 28,498
  • 28
  • 50
  • 59
Dan
  • 1,100
  • 2
  • 13
  • 36
  • Learning how to use a code section would surely improve your answers with minimum overhead. – zx485 Feb 11 '18 at 17:51
2

You can try something like this,

myListView.ItemTapped += (object sender, ItemTappedEventArgs e) => {    
   if (e.Item == null) return;     
    ((ListView)sender).SelectedItem = null; 
 }; 
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • It is still highlighting for a second, and if held down it stays highlighted – Dan Feb 11 '18 at 05:58
  • it seems to be a bug , try with https://stackoverflow.com/questions/35586243/xamarin-forms-untappable-listview-remove-selection-ripple-effect/36225591#36225591 – Sajeetharan Feb 11 '18 at 05:59
  • I used "Control.SetSelector(Android.Resource.Color.Transparent);" for android which seems to work – Dan Feb 11 '18 at 06:19
  • great! i have not done much xamarin, i was helping you with the existing answers – Sajeetharan Feb 11 '18 at 06:20
  • Just need to find a iOS fix though – Dan Feb 11 '18 at 06:21
  • check these links https://stackoverflow.com/questions/26657932/how-to-disable-highlight-on-listview-in-xamarin-forms – Sajeetharan Feb 11 '18 at 06:40
  • for IOS https://forums.xamarin.com/discussion/50783/how-i-can-disable-highlight-item-in-listview – Sajeetharan Feb 11 '18 at 06:40
  • @Daniel This is trying to solve the problem after the fact, youre racing the UI, the only way to solve this is by creating a non selectable renderer – TheGeneral Feb 11 '18 at 07:07
  • I used `Control.SetSelector(Android.Resource.Color.Transparent);` for Android and `cell.SelectionStyle = UITableViewCellSelectionStyle.None;` for iOS, which worked perfectly. – Dan Feb 11 '18 at 07:11