【问题标题】:Xamarin.Forms Error loading SVG Image using Data Binding using FFImageLoadingXamarin.Forms 使用 FFImageLoading 使用数据绑定加载 SVG 图像时出错
【发布时间】:2018-02-01 15:56:00
【问题描述】:

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

我的 XAML 中有图像绑定,我使用 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 >2.2.10-pre-428

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

在 Windows 10 Enterprise v1703 OS Build 15063.540 64 位上

【问题讨论】:

    标签: c# xamarin svg xamarin.forms ffimageloading


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-15
      • 2021-11-28
      • 1970-01-01
      • 2017-08-03
      • 2021-08-19
      • 1970-01-01
      • 2019-11-15
      相关资源
      最近更新 更多