我已经使用了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是qazxsw poi
IrrigNetDetailsPage.xaml.cs
<pages:PopupPage mlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup">
...
IrrigNetPage.xaml绑定(不起作用)
public partial class IrrigNetDetailsPage : PopupPage
{
public IrrigNetDetailsPage ()
{
InitializeComponent ();
BindingContext = new IrrigNetDetailsViewModel();
}
}
所以,我以与<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ShowIrrigNetDetailPageCommand}"/>
</Frame.GestureRecognizers>
和TabTappedCommand
相同的方式完成了所有事情,但很明显我错过了一些东西......
当您在方法中导航时,它需要是异步的。所以你的方法看起来像这样:
HideListOnTapCommand