【发布时间】:2017-07-08 04:47:53
【问题描述】:
我是 MVVM 的新手,我在 Xamarin.Forms 应用程序中出现了一些问题。
这是我在 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”的图像。
在这个视图的构造函数中,我添加了:
tapViewModel = new EasyScrum.Views.TapViewModel();
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
}
事件没有触发,怎么回事?
【问题讨论】:
标签: xaml xamarin mvvm xamarin.forms