绑定命令根本没有响应



我已经使用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();
    }
}

灌溉网视图模型.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")
        {
....

所以我以与ShowIrrigNetDetailPageCommand相同的方式完成了TabTappedCommand和HideListOnTapCommand的所有事情,但由于某种原因,当我点击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>

所以,我做所有事情的方式都与TabTappedCommandHideListOnTapCommand相同,但显然我错过了一些东西......

在方法中导航时,它需要异步。所以你的方法看起来像这样:

private async void ShowDetailPage()
    {
        Navigation.PushPopupAsync(new IrrigNetDetailsPage());
    }

相关内容

  • 没有找到相关文章

最新更新