О команде привязки для lanel TapGestureRecognizer, я делаю один пример, который вы можете посмотреть:
Во-первых, изменив обработчик команды для принятия параметра и изменив метод для принятия параметра команды.
public class RelayCommand1 : ICommand
{
private readonly Predicate<object> _canExecute;
private readonly Action<object> _execute;
public RelayCommand1(Action<object> execute)
: this(execute, null)
{
}
public RelayCommand1(Action<object> execute, Predicate<object> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute(parameter);
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
_execute(parameter);
}
}
Тогда используйте код:
<Label HorizontalOptions="CenterAndExpand" Text="Welcome to Xamarin.Forms!">
<Label.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding command1}"
CommandParameter="55"
NumberOfTapsRequired="1" />
</Label.GestureRecognizers>
</Label>
public partial class Page20 : ContentPage
{
public RelayCommand1 command1 { get; set; }
public Page20 ()
{
InitializeComponent ();
command1 = new RelayCommand1(obj => ChangeToTappedDate((string)obj));
this.BindingContext = this;
}
public void ChangeToTappedDate(string position)
{
int value = int.Parse(position);
Console.WriteLine("the position is {0}",value);
}
}