【问题标题】:Xamarin.Forms Long Press Effect - How to set the Command in Code Behind (NO XAML)Xamarin.Forms 长按效果 - 如何在代码后面设置命令(无 XAML)
【发布时间】:2018-11-14 15:30:33
【问题描述】:

我正在使用这个解决方案来处理长按事件: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?
};

【问题讨论】:

  • "无法从 'Xamarin.Forms.Command' 转换为 'Xamarin.Forms.Effect'"
  • _tgr 是什么,您应该将所有代码都放在原始帖子中,并写下您到目前为止尝试过的内容。为什么要尝试将效果添加为命令?
  • 我想单击以选择图片并长按以显示图片详细信息,例如文件大小等...

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


【解决方案1】:

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

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

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

其中myCommandICommand

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

【讨论】:

    猜你喜欢
    • 2016-05-16
    • 1970-01-01
    • 2012-03-30
    • 2016-12-08
    • 1970-01-01
    • 2019-05-07
    • 1970-01-01
    • 1970-01-01
    • 2017-02-09
    相关资源
    最近更新 更多