I have created listview using xamarin.forms, I am searching for a way not to highlight the viewcell while tapping on the listview.
please check on the image below.
Thanks in advance :)
Just put this in your custom theme:
<item name="android:colorActivatedHighlight">@android:color/transparent</item>
I'm using: ListView SelectionMode = "None"
in Xamarin.Forms.
on your ListView SelectedItem
event handler, you can do:
listview.SelectedItem = null;
that'll give you the on click highlight, but the state will be transient only.
In your case, I guess you'd like this because you're using 2 Image
s instead of Button
s for the arrows on the right, with a TapGestureRecognizer
. Do you know the Button
has an Image
property? When clicking on a Button
in a Cell
, the Cell
selected state shouldn't change.
I want to share another solution I really like, because it's simple, you have to implement it once and it's really easy to use in XAML.
First we have to implement our own behavior. That's quite simple:
public class DeselectItemBehavior : Behavior<ListView>
{
protected override void OnAttachedTo(ListView bindable)
{
base.OnAttachedTo(bindable);
bindable.ItemSelected += ListView_ItemSelected;
}
protected override void OnDetachingFrom(ListView bindable)
{
base.OnDetachingFrom(bindable);
bindable.ItemSelected -= ListView_ItemSelected;
}
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
((ListView)sender).SelectedItem = null;
}
}
So we're just registering to the event when the behavior is set and unregister it when it's unset.
The event itself uses Stephane Delcroix approach.
Now everything you have to do in the ListView is to add the behavior like this:
<ListView ...>
<ListView.Behaviors>
<behaviors:DeselectItemBehavior />
</ListView.Behaviors>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With