1
我是MVVM的新手,並且在我的Xamarin.Forms應用中出現了一些問題。Xamarin ICommand沒有解僱
下面是我在SessionsPage.xml
<Grid.Children>
<Image Source="zero.jpg" Grid.Row="0" Grid.Column="0">
<Image.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding TapCommand}"
CommandParameter="0" />
</Image.GestureRecognizers>
我有一個鏈接到命令「TapCommand」的圖像。
在該視圖的構造函數中,我說:
而且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
}
,而該事件不觸發,有什麼不好?