Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public static class AttachedItemTappedBehavior
public static readonly BindableProperty CommandProperty =
propertyName: "Command",
returnType: typeof(ICommand),
declaringType: typeof(ListView),
defaultValue: null,
defaultBindingMode: BindingMode.OneWay,
validateValue: null,
propertyChanged: OnItemTappedChanged);
private static void OnItemTappedChanged(BindableObject bindable, object oldValue, object newValue)
=> (bindable as ListView).ItemTapped += (sender, e) =>
var control = sender as ListView;
var command = (ICommand)control.GetValue(CommandProperty);
if (command != null && command.CanExecute(e.Item))
control.SelectedItem = null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment