Xamarin.Forms长按效果 - 如何在代码背后设置命令(NO XAML)

时间:2018-06-05 08:03:23

标签: c# xamarin.forms command long-press

我正在使用此解决方案处理长抽头活动:https://alexdunn.org/2017/12/27/xamarin-tip-xamarin-forms-long-press-effect/

当我使用XAML时它工作正常,但我只需要使用代码。如何将此命令添加到后面代码中的Image

以下是创建我的图片的代码:

var image = new Image
{
    ClassId = item.Path,
    Aspect = Aspect.AspectFill,
    Source = item.ThumbNailImage,
    Rotation = 90,
    Margin = 10,
    GestureRecognizers = { _tgr },
    //Command here, but how?
};

1 个答案:

答案 0 :(得分:0)

微软网站上的

This documentation非常有助于解释如何在代码中设置附加属性。

因此,根据示例,您的代码应如下所示:

image.Effects.Add(new LongPressedEffect());
LongPressedEffect.SetCommand(image, myCommand);

其中myCommandICommand

这应创建LongPressedEffect,将其添加到图片,然后设置确定行为的附加ICommand

相关问题