[英]How to handle the Tap of a ViewCell defined in code in Xamarin.Forms?
我在TableView中有多個ViewCell和ImageCell子類。
當用戶點擊單元格時,我想執行一些代碼。 只要觸摸它,整個單元格就會突出顯示,但我看不到要使用的任何事件處理程序。
是否沒有XAML Tapped等效項,僅在代碼中?
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可以處理此問題。 也許我只是找不到合適的位置?
謝謝!
這可以通過在單元格的視圖布局中添加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;
編輯:
或者,使用ViewCell的Tapped屬性更好的選擇,這樣就不會破壞“ Tap Animation”:
Tapped += new EventHandler((e, s) => {
if (command.CanExecute(null))
{
command.Execute(null);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.