Xamarin.forms 如何使用FFImageLoading在Xamarin表单中实现UWP自定义渲染器

Xamarin.forms 如何使用FFImageLoading在Xamarin表单中实现UWP自定义渲染器,xamarin.forms,uwp,custom-renderer,ffimageloading,Xamarin.forms,Uwp,Custom Renderer,Ffimageloading,我找不到在xamarin表单的UWP自定义渲染器中使用FFImageLoading的好例子,好的例子站点只在android和ios中使用。我的主要问题是如何在UWP资源中使用这个Image类,如果我理解正确,应该在PCL项目中使用CacheDiImage。那么我应该如何继续?ImageService的提前使用并未详细说明这一点。我可能不明白什么。提前谢谢 这是PCL中的“我的视图”单元格: <ViewCell> <Grid RowSpacing="0" Padding="5,1

我找不到在xamarin表单的UWP自定义渲染器中使用FFImageLoading的好例子,好的例子站点只在android和ios中使用。我的主要问题是如何在UWP资源中使用这个Image类,如果我理解正确,应该在PCL项目中使用CacheDiImage。那么我应该如何继续?ImageService的提前使用并未详细说明这一点。我可能不明白什么。提前谢谢

这是PCL中的“我的视图”单元格:

<ViewCell>
<Grid RowSpacing="0" Padding="5,1,10,1">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="60"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
        <ColumnDefinition Width="30"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="32"></RowDefinition>
        <RowDefinition Height="32"></RowDefinition>
    </Grid.RowDefinitions>
    <ffimageloading:CachedImage Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Source="{Binding MyViewModel.Image}" Aspect="AspectFit" VerticalOptions="Center" LoadingPlaceholder = "resource://MyProject.Resources.loading.png" />
    <Label Grid.Column="1" Grid.Row="0" Text="{Binding MyViewModel.Name}" FontSize="16" TextColor="Red" FontAttributes="Bold" VerticalOptions="End"></Label>
    <Label Grid.Column="1" Grid.Row="1" Text="{Binding MyViewModel.Serie}" FontSize="11" TextColor="Gray" FontAttributes="Italic" VerticalOptions="Start"></Label>
    <ffimageloading:CachedImage x:Name="check" Grid.Column="2" Grid.Row="0" Grid.RowSpan="2" Source="{Binding MyViewModel.Own, Converter={StaticResource BoolToOwnImageSourceConverter}}}" Aspect="AspectFit" VerticalOptions="Center">
        <Image.GestureRecognizers>
            <TapGestureRecognizer
                Tapped="OnCheckTapped"
                Command="{Binding ChangeOwnCommand}"
                CommandParameter="{Binding .}"/>
        </Image.GestureRecognizers>
    </ffimageloading:CachedImage>
</Grid>
<ViewCell.ContextActions>
    <MenuItem Clicked="OnOwned"     CommandParameter="{Binding .}" Text="Got it!" />
    <MenuItem Clicked="OnNotOwned"  CommandParameter="{Binding .}" Text="Not Yet"    IsDestructive="True" />
</ViewCell.ContextActions>

图像源来自存储在我的视图模型中的图像url

我的主要问题是如何在UWP资源中使用这个图像类

如果要自定义图像渲染器。您可以展开xamarin图像的属性

public class CustomImage : Image
{
    public static readonly BindableProperty UriProperty = BindableProperty.Create(
propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(CustomImage),
defaultValue: default(string));

    public string Uri
    {
        get { return (string)GetValue(UriProperty); }
        set { SetValue(UriProperty, value); }
    }

}
您可以调用
LoadUrl
,在自定义图像渲染中为本机控件设置图像

protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
{
    base.OnElementChanged(e);
    var customImage = (CustomImage)Element;

    if (Control == null)
    {
        SetNativeControl(new Windows.UI.Xaml.Controls.Image());

    }
    if (e.OldElement != null)
    {

    }
    if (e.NewElement != null)
    {
        if (!string.IsNullOrEmpty(customImage.Uri))
        {
            ImageService.Instance.LoadUrl(customImage.Uri).FadeAnimation(true).Into(Control);
        }
        else
        {
            // do some stuff
        }
    }
}
protected override void OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
var customImage=(customImage)元素;
if(Control==null)
{
SetNativeControl(新的Windows.UI.Xaml.Controls.Image());
}
if(e.OldElement!=null)
{
}
if(例如NewElement!=null)
{
如果(!string.IsNullOrEmpty(customImage.Uri))
{
ImageService.Instance.LoadUrl(customImage.Uri).FadeAnimation(true).Into(控件);
}
其他的
{
//做点什么
}
}
}

是否要使用ffimageLoding实现自定义图像渲染器?是的,我的listview>1000个项目,每个单元格有2个图像,需要平滑加载。您可以分享有关图像源的更多详细信息吗?@NicoZhu MSFT它来自存储在我的视图模型中的图像url,加载图像作为嵌入资源存储在pcl中,你能用从LocalResource pls添加LoadingPlaceholder的方式来更新它吗?我使用很少的作为嵌入资源