Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml Xamarin i命令未开火_Xaml_Xamarin_Mvvm_Xamarin.forms - Fatal编程技术网

Xaml Xamarin i命令未开火

Xaml Xamarin i命令未开火,xaml,xamarin,mvvm,xamarin.forms,Xaml,Xamarin,Mvvm,Xamarin.forms,我是MVVM新手,在我的Xamarin.Forms应用程序中出现了一些错误 下面是我在sessionpage.xml中看到的内容 <Grid.Children> <Image Source="zero.jpg" Grid.Row="0" Grid.Column="0"> <Image.GestureRecognizers> <TapGestureRecognizer Command="{Bindin

我是MVVM新手,在我的Xamarin.Forms应用程序中出现了一些错误

下面是我在sessionpage.xml中看到的内容

<Grid.Children>
    <Image Source="zero.jpg" Grid.Row="0" Grid.Column="0">
    <Image.GestureRecognizers>
        <TapGestureRecognizer
            Command="{Binding TapCommand}"
            CommandParameter="0" />
     </Image.GestureRecognizers>
而ViewModel类是:

public class TapViewModel : INotifyPropertyChanged
{
    int taps = 0;
    ICommand tapCommand;

    public event PropertyChangedEventHandler PropertyChanged;

    public TapViewModel()
    {
        // configure the TapCommand with a method
        tapCommand = new Command(OnTapped);
    }

    public ICommand TapCommand
    {
        get { return tapCommand; }
    }
    void OnTapped(object s)
    {
        taps++;
        Debug.WriteLine("parameter: " + s);
    }
    //region INotifyPropertyChanged code omitted
}
事件没有触发,怎么了?

我回答自己

我的错误是我必须分配

this.BindingContext=新的TapViewModel()

public class TapViewModel : INotifyPropertyChanged
{
    int taps = 0;
    ICommand tapCommand;

    public event PropertyChangedEventHandler PropertyChanged;

    public TapViewModel()
    {
        // configure the TapCommand with a method
        tapCommand = new Command(OnTapped);
    }

    public ICommand TapCommand
    {
        get { return tapCommand; }
    }
    void OnTapped(object s)
    {
        taps++;
        Debug.WriteLine("parameter: " + s);
    }
    //region INotifyPropertyChanged code omitted
}