CoverFlowView内部未显示灰度图像[Xamarin Forms iOS]

问题描述

我目前正在通过使用此nuget进行Coverflowview: https://github.com/AndreiMisiukevich/CardView

当我使用常规图像或cachedimage(ffimageloading nuget)时,绑定效果很好。但是现在我尝试使用自定义控件对图像进行灰度处理。我成功运行了代码以对其进行灰度处理(当属性更改为IsSelectable true时),但是由于某种原因,图像根本无法显示,如果我删除了灰度逻辑,则图像可以很好地显示

 <cards:CoverFlowView PositionShiftValue="40"
                                         ItemsSource="{Binding Items}"
                                         VerticalOptions="FillAndExpand"
                                         HeightRequest="360">
                    <cards:CoverFlowView.ItemTemplate>
                        <DataTemplate>
                            <AbsoluteLayout HeightRequest="360">
                                 
                               <controls:GrayScaleImage Aspect="AspectFill"
                                                        AbsoluteLayout.LayoutBounds="0.0,0.5,1,1"
                                                        AbsoluteLayout.LayoutFlags="All"
                                                        Source="{Binding ProgramDeserialized.Image}"
                                                        IsSelectable="{Binding IsSelectable}"/>
                           </AbsoluteLayout>
                        </DataTemplate>
                    </cards:CoverFlowView.ItemTemplate>
                </cards:CoverFlowView>

自定义控件:

public class GrayScaleImage : CachedImage
{
    public static BindableProperty IsSelectableProperty = BindableProperty.Create(nameof(IsSelectable),typeof(bool),typeof(GrayScaleImage),true,propertyChanged: UpdateImage);
    
    public bool IsSelectable
    {
        get { return (bool)GetValue(IsSelectableProperty); }
        set { SetValue(IsSelectableProperty,value); }
    }
    
    private static void UpdateImage (BindableObject bindable,object oldColor,object newColor)
    {
        
        var view = (GrayScaleImage)bindable;
        if (!view.IsSelectable)
        {
            var transformations = new System.Collections.Generic.List<ITransformation>() {
                new GrayscaleTransformation()
            };
            view.Transformations = transformations;
        }
        
    }
}

不确定可能是什么问题。当我在常规的stacklayout可绑定列表上执行此操作,并应用相同的逻辑时,它可以正常工作,所以我的直觉是Coverflowview nuget出现了一些问题。

解决方法

您如何设置图像的绑定?我创建了一个示例来测试功能代码,grayScale图像工作正常。

检查屏幕截图:
https://us.v-cdn.net/5019960/uploads/editor/ab/jqki5zvo7cfw.gif

这是有关模型类和viewModel类的代码,您可以参考它。

public class CustomModel
{
    public Xamarin.Forms.ImageSource MyImage { get; set; }
    public bool IsSelectable { get; set; }
}

public class CustomViewModel
{
    public ObservableCollection<CustomModel> Items { get; set; }

    public CustomViewModel()
    {
        Items = new ObservableCollection<CustomModel>();
        //add the data
    }
}