下面是我目前在C#中做的事情:
TapGestureRecognizer tap = new TapGestureRecognizer()
{
NumberOfTapsRequired = 1
};
tap.SetBinding(TapGestureRecognizer.CommandProperty, new Binding("DeckTapCommandAsync", source: GD));
tap.SetBinding(TapGestureRecognizer.CommandParameterProperty, new Binding("TapCommandParam", source: GD));
GestureRecognizers.Add(tap);我想知道的是,是否有任何使用Xamarin.Forms C#标记的方法可以做到这一点
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/csharp-markup
发布于 2020-06-29 13:22:34
是的,您可以为TapGestureRecognizer使用SetBinding。
使用ICommand:
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.SetBinding (TapGestureRecognizer.CommandProperty, "TapCommand");
image.GestureRecognizers.Add(tapGestureRecognizer);有关更多详细信息,请查看链接:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/gestures/tap#using-icommand
您可以从以下链接下载源文件:https://docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/workingwithgestures-tapgesture/
或者,您可以使用以下命令进行设置:
// Image TRASH
TapGestureRecognizer tgrTrash = new TapGestureRecognizer();
tgrTrash.SetBinding(TapGestureRecognizer.CommandProperty, new Binding("BindingContext.TrashCommand", source: this));
tgrTrash.SetBinding(TapGestureRecognizer.CommandParameterProperty, ".");
Image imageTrash = new Image() { Source = "trash.png" };
//Label lTrash = new Label { Text = "Trash", VerticalTextAlignment = TextAlignment.Center };
imageTrash.GestureRecognizers.Add(tgrTrash);您可以从以下链接下载源文件:https://github.com/WendyZang/TestBindingWithListView
https://stackoverflow.com/questions/62611138
复制相似问题