2017-09-16 3 views
0

私のコードは、現在、バックエンドのC#私も含め偽のパラメータにXAMLでこれを追加することができますどのようにパラメータを持つtapGestureRecognizerを追加するにはどうすればよいですか?

deselectGridLink.GestureRecognizers.Add(NewTapGestureForUpdateCategories(false)); 

    private TapGestureRecognizer NewTapGestureForUpdateCategories(bool val) 
    { 
     return new TapGestureRecognizer() 
     { 
      Command = new Command(() => 
      { 
       App.DB.UpdateAllCategoryGroups(val); 
       App.DB.UpdateAllCategories(val); 
       GetPageData(); 
       RemoveTableViewClickSection(); 
       tableView.Root.Add(CreateTableSection()); 
       SetPageDetails(); 
      }) 
     }; 
    } 

でこれを追加します。私は何とかXAMLにこれを追加する場合にも、私はC#のFのNewTapGestureForUpdateCategories方法を?:変更する必要があります

<Grid x:Name="deselectGridLink" VerticalOptions="CenterAndExpand" Padding="20, 0"> 
    <Label TextColor="Blue" Style="{DynamicResource ListItemTextStyle}" x:Name="deselectLink" HorizontalOptions="StartAndExpand" VerticalOptions="Center" Text="Deselect All" /> 
</Grid> 

答えて

1

XAML:

<Grid x:Name="deselectGridLink" VerticalOptions="CenterAndExpand" Padding="20, 0"> 
    <Label TextColor="Blue" 
      Style="{DynamicResource ListItemTextStyle}" 
      x:Name="deselectLink" 
      HorizontalOptions="StartAndExpand" 
      VerticalOptions="Center" 
      Text="Deselect All" > 
    <Label.GestureRecognizers> 
     //!!!!!!!!!!!!!!!!!!!!!!!!!set parameter here. 
     <TapGestureRecognizer Command="{Binding TapCommand}" CommandParameter="false"/> 
    </Label.GestureRecognizers> 

    </Label> 
</Grid> 

コードの背後にある:あなたが設定

public partial class YourPage : ContentPage 
{ 
    public Command TapCommand 
    { 
     get 
     { 
      return new Command(val => { 
       DisplayAlert("Alert", val.ToString(), "OK"); 
      }); 
     } 
    } 

    public YourPage() 
    { 
     InitializeComponent(); 
     this.BindingContext = this; 
    } 
} 

Label.GestureRecognizersのCommandParameterにある場合、コードビハインドのTapCommandがそれを受け取ることができます。

+0

コマンドパラメータがコードビハインドでどのように使用されているか説明できますか。私はあなたがそれを説明するのを忘れたかもしれないと思う。ありがとうございました – Alan2

+0

@ Alan2 'CommandParameter'を参照してください。 'CommandParameter'を直接参照するだけで、 'CommandParameter =" {Binding isVal} "'を使用してコード内にisValプロパティを設定することもできます。 –

+0

こんにちは、これをXAMLとC#に追加することができますので、trueまたはfalseをTapCommandに渡す方法や、trueまたはfalseを表示するためにTapCommandをどのように変更するかを示しています。ありがとう – Alan2

関連する問題