Xaml Xamarin i命令未开火
我是MVVM新手,在我的Xamarin.Forms应用程序中出现了一些错误 下面是我在sessionpage.xml中看到的内容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
<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
}