Xamarin.Forms GestureRecognizers 添加 shorthand?

Xamarin.Forms GestureRecognizers add shorthand?

下面的代码可以进一步简化吗?

var onLogoutTap = new TapGestureRecognizer();
onLogoutTap.Tapped += (object sender, EventArgs e) => {
    MessagingCenter.Send(this, "Logout");
};
logoutImage.GestureRecognizers.Add(onLogoutTap);

能否以某种方式将 .Tapped... 部分直接传递给 TapGestureRecognizer()

是的。 TapGestureRecognizer有多个constructors,可以传一个回调。

var onLogoutTap = new TapGestureRecognizer(_ => MessagingCenter.Send(this, "Logout"));