我有一個擴展器并想在其子級中呼叫它的命令(還有另一個控制器覆寫了觸摸手勢,這就是為什么我需要再次覆寫它并呼叫父級的觸摸事件)
所以我添加了一個網格,我希望當我觸摸網格時,應該呼叫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# 也可以。
編輯:我收到這個警告
系結:“MyProject.Forms.ViewElements.Controls.ExtendedExpander”無法轉換為型別“System.Windows.Input.ICommand”
uj5u.com熱心網友回復:
加入; Path=<Name of command property>_ GestureRecognizer見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}"
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/453558.html
下一篇:如何在導航視圖中隱藏滾動條
