mvvm - 绑定命令根本没有响应
问题描述
我已经使用TapGestureRecognizer
并将它们绑定到某个命令并且该命令工作正常......
这是示例:
IrrigNetPage.xaml(查看)
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TabTappedCommand}" CommandParameter="map"/>
</StackLayout.GestureRecognizers>
<Grid IsVisible="{Binding IsGridHeaderVisible}">
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding HideListOnTapCommand}"/>
</Grid.GestureRecognizers>
</Grid>
IrrigNetPage.xaml.cs
public partial class IrrigNetPage : ContentPage
{
public IrrigNetPage ()
{
InitializeComponent ();
BindingContext = new IrrigNetViewModel();
}
}
IrrigNetViewModel.cs
[AddINotifyPropertyChangedInterface]
public class IrrigNetViewModel : PopupPage
{
public ICommand TabTappedCommand { get; }
public ICommand HideListOnTapCommand { get; }
public ICommand ShowIrrigNetDetailPageCommand { get; }
public IrrigNetViewModel()
{
TabTappedCommand = new Command((tabName) => OnTapClicked(tabName.ToString()));
HideListOnTapCommand = new Command(HideListOnTap);
ShowIrrigNetDetailPageCommand = new Command(ShowDetailPage);
private void ShowDetailPage()
{
Navigation.PushPopupAsync(new IrrigNetDetailsPage());
}
private void HideListOnTap()
{
IsListVisible = !IsListVisible;
}
private void OnTapClicked(string tabName)
{
if (tabName == "location")
{
....
所以我对 TabTappedCommand 和 HideListOnTapCommand 以与 ShowIrrigNetDetailPageCommand 相同的方式完成了一切,但由于某种原因,当我点击 TapGestureRecognizer 时什么也没有发生。我试图调试,但我没有得到任何异常或错误......只是没有发生任何事情......
我安装了 Rg.Plugins.Popup,因为 IrrigNetDetailsPage.xaml 是<pages:PopupPage mlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup">
...
IrrigNetDetailsPage.xaml.cs
public partial class IrrigNetDetailsPage : PopupPage
{
public IrrigNetDetailsPage ()
{
InitializeComponent ();
BindingContext = new IrrigNetDetailsViewModel();
}
}
IrrigNetPage.xaml 绑定(不起作用)
<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ShowIrrigNetDetailPageCommand}"/>
</Frame.GestureRecognizers>
TabTappedCommand
因此,我以与 and相同的方式完成了所有操作HideListOnTapCommand
,但显然我遗漏了一些东西...
解决方案
当你在一个方法中导航时,它需要是异步的。所以你的方法看起来像这样:
private async void ShowDetailPage()
{
Navigation.PushPopupAsync(new IrrigNetDetailsPage());
}
推荐阅读
- c# - 如何访问 Android 模拟器中的本地文件夹以检索 SQLite 数据库?
- c++ - 如果我写的太多,C++ fstream 在关闭文件时抛出异常
- php - 启用 wordpress 多站点会中断数据库连接
- gitlab - Gitlab Sonar Qube 重定向网址
- python - 使用插值重新索引 Pandas DataFrame
- typescript - “AsyncThunkAction”类型上不存在 Redux 工具包属性“then”
- vue.js - 如何在 vuejs 中打开 pdf 文件?
- c# - ConfigurationManager.ConnectionStrings["Web"].ConnectionString 为 NULL ASP NET CORE MVC 3.1
- php - 在幽灵脚本完成之前,服务器访问一直被阻止
- elasticsearch - Elasticsearch 是否支持 postgis 中的 ST_DWithin 等地理查询