在Xaml中的child中调用parent命令在Xamarin.Forms中

Calling the parent command in the child in Xaml in Xamarin.Forms

我有一个扩展器,想在其 child 中调用它的命令(还有另一个控制器覆盖触摸手势,这就是为什么我需要再次覆盖它并调用 parent' s 触摸事件)

所以我添加了一个网格,我希望当我触摸网格时,应该调用 Expander 的命令(即 ExpanderTappedCommand)(及其参数)

这是我的代码,但它不起作用

<controls:ExtendedExpander
        Command="{Binding Path=BindingContext.ExpanderTappedCommand, Source={x:Reference this}}"
        CommandParameter="{Binding .}"
        AdditionalCommandParameter="{Binding Source={x:Reference stackLayout}}">
     <xct:Expander.Header>

         ......

      <Grid.GestureRecognizers>
          <TapGestureRecognizer                                             
            Command="{Binding Source={RelativeSource AncestorType={x:Type xct:Expander}}}"/>
     </Grid.GestureRecognizers>

    </Grid>

PS: Xaml 不是强制性的。可以的话c#也行

编辑: 我收到这个警告

Binding: 'MyProject.Forms.ViewElements.Controls.ExtendedExpander' cannot be converted to type 'System.Windows.Input.ICommand'

GestureRecognizer中添加Path=<Name of command property>;请参阅下面的 CollectionView 示例:

<CollectionView 
  ...
  RemainingItemsThresholdReachedCommand="{Binding Source={RelativeSource                                                        
                                                    AncestorType={x:Type vm:MyViewModel}},
                                                  Path=ThresholdReachedCommand}"
  ...
<Grid>
  <Grid.GestureRecognizers>
    <TapGestureRecognizer Command="{Binding Source={RelativeSource 
                                              AncestorType={x:Type CollectionView}},
                                            Path=RemainingItemsThresholdReachedCommand}" 
  ...