首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我可以使用Xamarin的新C#标记添加tap.SetBinding吗?

我可以使用Xamarin的新C#标记添加tap.SetBinding吗?
EN

Stack Overflow用户
提问于 2020-06-27 22:13:43
回答 1查看 40关注 0票数 0

下面是我目前在C#中做的事情:

代码语言:javascript
复制
        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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-29 13:22:34

是的,您可以为TapGestureRecognizer使用SetBinding

使用ICommand:

代码语言:javascript
复制
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/

或者,您可以使用以下命令进行设置:

代码语言:javascript
复制
// 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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62611138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档