Xamarin.Forms使用FFImageLoading使用数据绑定加载SVG图像时出错

时间:2017-08-23 22:29:02

标签: c# xamarin svg xamarin.forms ffimageloading

我正在使用Xamarin.FFImageLoading.Svg.Forms Nuget包。

我在XAML中有Image Bindings,我正在使用ListView.ItemTemplate一次渲染多个菜单项。

<ffimageloadingsvg:SvgCachedImage 
 WidthRequest="50" 
 HeightRequest="50" 
 Source="{Binding ImageSource}"/>

包含SVG路径数据的ViewModel。我已经尝试了几种方法,你可以看到(大多数用于测试目的)并且它们都失败了。

MenuItems = new ObservableCollection<MenuItem>(new[]
{                   
     new MenuItem { Id = 1,
                    Title = "Facility Info",
                    CommandParameters = "",
                    ImageSource = Xamarin.Forms.ImageSource.FromResource("myMTC.Assets.Images.user.svg") },
     //new MenuItem { Id = 2,
                    //    Title = "Workshops",
                    //    CommandParameters = "",
                    //    ImageSource = SVG_ASSET_PATH + "user.svg" },
     //new MenuItem { Id = 3,
                    //    Title = "Feedback",
                    //    CommandParameters = "",
                    //    ImageSource = Xamarin.Forms.ImageSource.FromResource("myMTC.Assets.Images.user.svg") },
     //new MenuItem { Id = 4,
                    //    Title = "Artifacts",
                    //    CommandParameters = "",
                    //    ImageSource = Xamarin.Forms.ImageSource.FromFile("ms-appx:///Assets/Images/user.svg") },
     //new MenuItem { Id = 4,
                    //    Title = "Action Items",
                    //    CommandParameters = "",
                    //    ImageSource = new Uri(SVG_ASSET_PATH + "Droid.saction-items.svg") },
            });

似乎错误已植根于ImagerLoaderTask API

中的某个位置

ffimageloading\source\FFImageLoading.Common\Work\ImageLoaderTask.cs:463

--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <401c12b575cb4781b0a9e010ed5a0221>:0 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <401c12b575cb4781b0a9e010ed5a0221>:0 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <401c12b575cb4781b0a9e010ed5a0221>:0 
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <401c12b575cb4781b0a9e010ed5a0221>:0 
08-23 14:41:49.328 I/mono-stdout( 5366):   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <401c12b575cb4781b0a9e010ed5a0221>:0 
08-23 14:41:49.328 I/mono-stdout( 5366):   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <401c12b575cb4781b0a9e010ed5a0221>:0 
08-23 14:41:49.328 I/mono-stdout( 5366):   at FFImageLoading.Work.ImageLoaderTask`2+<RunAsync>d__109[TImageContainer,TImageView].MoveNext () [0x00435] in C:\projects\ffimageloading\source\FFImageLoading.Common\Work\ImageLoaderTask.cs:463

运行FFImageLoading release &GT; 2.2.10-pre-428

VS2017 Enterprise(有时也使用预览版)

在Windows 10 Enterprise v1703 OS Build 15063.540 64位

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,并且能够通过将svg放在Drawables文件夹中,将其设置为AndroidResource,然后直接通过文件名引用它来实现它:

MenuItems = new ObservableCollection<MenuItem>(new[]
{                   
     new MenuItem { Id = 1,
                Title = "Facility Info",
                CommandParameters = "",
                ImageSource = "user.svg" }
}