代码之家  ›  专栏  ›  技术社区  ›  DarkW1nter

Xamarin表单-在点击手势识别器上添加调用对象作为参数

  •  0
  • DarkW1nter  · 技术社区  · 7 年前

    在下面的XAML中添加图像作为命令参数的正确语法是什么?

    <ffimageloading:CachedImage Source="{Binding Source}" Aspect="AspectFit" CacheType="Memory" Opacity="2" x:Name="smallImage" >
                                <Image.GestureRecognizers>
                                    <TapGestureRecognizer 
                                        Command="{Binding Path=BindingContext.SetImageCommand, Source={x:Reference this}}"
                                        CommandParameter="{Binding smallImage}" />
                                </Image.GestureRecognizers>
                            </ffimageloading:CachedImage>
    

    将有多个调用图像的实例,因为它作为图像滑块的一部分在数据模板中,所以我不能只按名称获取控件,我必须确保传递的是调用控件。

    public ICommand SetImageCommand
            {
                get
                {
                     return new Command<CustomCachedImage>((_image) =>
                     {
                         string imgName = _image.ImageName;
                         SetImg(imgName);
                     });
                 }
            }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   DarkW1nter    7 年前

    将“{Binding smallImage}”更改为“{Binding.}”,我得到了所需的内容