【发布时间】:2019-07-30 04:57:02
【问题描述】:
我已经使用 TapGestureRecognizer 在 StackLayout 上添加了一个命令,但它没有调用 viewmodel 类。
这是 xaml 代码:
<StackLayout Padding="10" Spacing="0">
<Image Source="edit_black" WidthRequest="20" />
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding EditServiceCommand}" CommandParameter="{Binding .}" />
</StackLayout.GestureRecognizers>
</StackLayout>
ViewModel 类命令方法:
public ICommand EditServiceCommand
{
get => new Command((item) => { _popupNavigation.PushAsync(new AddServicePopup("edit"), true); });
}
【问题讨论】:
-
您是否已经将页面绑定上下文分配给您的视图模型?
-
是的,我用的是棱镜
-
您是如何在 prism 中注册视图模型的?你的视图模型的构造函数被调用了吗?
-
Viewmodel 正在工作,我可以从 viewmodel 中获取列表。
-
如果您使用的是 Prism,您可能需要使用 DelegateCommand
标签: xamarin mvvm xamarin.forms navigation