FFImageLoading: [Xamarin.Forms Android] Error loading SVG Image through Data Binding
It appears that data binding is possible for SVGs. I’m taking a different approach loading SVGs through data binding.
I have them all in a file structure like the below
Assets
> Images
> image-name.svg
Then I have the Images bound in my XAML
<ffimageloadingsvg:SvgCachedImage
WidthRequest="50"
HeightRequest="50"
Source="{Binding ImageSource}"/>
And a ViewModel containing the path data for the SVGs. I’ve tried several approaches as you can see (commented most out for testing purposes) and they all fail 😢 .
MenuItems = new ObservableCollection<MenuItem>(new[]
{
new MenuItem { Id = 1,
Title = "Facility Info",
CommandParameters = "",
ImageSource = Xamarin.Forms.ImageSource.FromResource("resource://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") },
});
It appears the error is rooted somewhere in the 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
Running
Release > 2.2.10-pre-428
.
VS2017 Enterprise (using preview sometimes too)
on
Windows 10 Enterprise v1703 OS Build 15063.540 64 bit
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (7 by maintainers)
If you use assets located in PCL you can use following image sources:
"resource://myMTC.Assets.Images.user.svg"
(string)new EmbeddedResourceImageSource("myMTC.Assets.Images.user.svg")
ImageSource.FromResource("myMTC.Assets.Images.user.svg")
(least efficient one)If it’s located in a different assembly than your app, then you must also specify correct assembly:
"resource://myMTC.Assets.Images.user.svg?assembly=[FULL ASSEMBLY NAME]"
(string)new EmbeddedResourceImageSource("myMTC.Assets.Images.user.svg", assembly)
ImageSource.FromResource("myMTC.Assets.Images.user.svg", assembly)
(least efficient one)That’s all.
There are built in converters, just pass a
string
resource://myMTC.Assets.Images.user.svg
.EmbeddedResourceImageSource
is alsoXamarin.Forms.ImageSource