我正在使用此解决方案处理长抽头活动: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?
};
答案 0 :(得分:0)
This documentation非常有助于解释如何在代码中设置附加属性。
因此,根据示例,您的代码应如下所示:
image.Effects.Add(new LongPressedEffect());
LongPressedEffect.SetCommand(image, myCommand);
其中myCommand
是ICommand
。
这应创建LongPressedEffect
,将其添加到图片,然后设置确定行为的附加ICommand
。