FFImageLoading : 加载到 ImageButton

Per*_*ror 3 xamarin.android xamarin ffimageloading

在 Xamarin.Android 中,若要使用 FFImageLoading 加载图像,必须使用 ImageViewAsync 而不是标准 ImageView。

如果我想将图像加载到 ImageButton 中,我找不到可以使用的内容。没有找到“ImageButtonAsync”。

Car*_*ice 5

不知道这是否相关。我给了我的 svg 一个点击手势,让它像按钮一样工作。

首先在你的 xaml 中引用 FFImageLoading.Svg.Forms

namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms"
Run Code Online (Sandbox Code Playgroud)

第二个使用点击手势添加 svgImage

    <ffimageloadingsvg:SvgCachedImage Source="YourImageSource" >
                    <ffimageloadingsvg:SvgCachedImage.GestureRecognizers>
                        <TapGestureRecognizer NumberOfTapsRequired="1" Command="{Binding YourCommand}"/>
                    </ffimageloadingsvg:SvgCachedImage.GestureRecognizers>
    </ffimageloadingsvg:SvgCachedImage>
Run Code Online (Sandbox Code Playgroud)

您将在 ViewModel 的构造函数中调用它来初始化命令

YourCommand= new DelegateCommand(async () => await ExecuteYourCommandAsync());
Run Code Online (Sandbox Code Playgroud)

创建绑定到 xaml 文件的属性

    public ICommand YourCommand
    {
        get => yourCommand;
        set => SetProperty(ref yourCommand, value);
    }

    private ICommand yourCommand;
Run Code Online (Sandbox Code Playgroud)

await ExecuteYourCommandAsync 是您创建的方法。并在其中放置您实际希望点击手势执行的操作的逻辑。

您还可以使用命令传递对象。让我知道这是否有意义