2016-12-05 1 views
0

私は、ViewView内に複数のViewCellサブクラスとImageCellサブクラスを持っています。Xamarin.Formsのコードで定義されているViewCellのTapを処理する方法は?

ユーザーがセルをタップしたときにいくつかのコードを実行したいと思います。タッチされるたびにセル全体がハイライト表示されますが、ここで使用するイベントハンドラは表示されません。

これにはXAML Tapped同等物はありませんが、コード内にのみ存在しますか?

enter image description here

private void SetTableView() 
    { 
     Content = new TableView 
     { 
      HasUnevenRows = true, 
      Intent = TableIntent.Menu, 
      Root = new TableRoot() 
      { 
       new TableSection() 
       { 
        new ProfileCell(ImageSource.FromFile("profile_placeholder.png"), "Casa de Férias") 
       }, 
       new TableSection() 
       { 
        new InfoCell() 
        { 
         Type = InfoCellTypes.Pending, 
         Text = "Avaliação do Imóvel", 
         Detail = "Estado do Processo" 
        } 
       } 
      } 

     }; 

    } 

私はこれを処理し、いくつかのAPIが存在しなければならないと確信しています。たぶん、私はちょうどいい場所で探していないのですか?

ありがとうございました!

答えて

2

これは、セルのビューレイアウトにTapGestureRecognizerを追加することで実現できます。

var absoluteLayout = new AbsoluteLayout 
{ 
    Children = 
    { 
     photo, 
     editImage, 
     label 
    } 
}; 

var tapGestureRecognizer = new TapGestureRecognizer(); 
tapGestureRecognizer.NumberOfTapsRequired = 1; 
tapGestureRecognizer.Tapped += (s, e) => { 
    // handle the tap 
}; 

absoluteLayout.GestureRecognizers.Add(tapGestureRecognizer); 

View = absoluteLayout; 

EDIT:

それとも、より良い代替手段、それは "タップアニメーション" を破壊しないので、ViewCellのタッププロパティを使用して:

Tapped += new EventHandler((e, s) => { 

    if (command.CanExecute(null)) 
    { 
     command.Execute(null); 
    } 

});