如何解决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
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。