aurora/Aurora/Design/Extensions/ImageResourceExtension.cs

43 lines
1.2 KiB
C#
Raw Normal View History

2019-12-03 19:31:02 +00:00
using System;
using System.Linq;
using System.Reflection;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Aurora.Design.Extensions
{
[ContentProperty(nameof(Source))]
public class ImageResourceExtension : IMarkupExtension
{
public string Source { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Source == null)
{
return null;
}
Assembly[] referencedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
var gtkAsm = referencedAssemblies.FirstOrDefault((e) =>
{
return e.FullName.Contains("Aurora.gtk");
});
foreach (var res in gtkAsm.GetManifestResourceNames())
{
Console.WriteLine("found resource: " + res);
2019-12-03 19:31:02 +00:00
}
if (gtkAsm == null && gtkAsm is Assembly)
{
return null;
}
// Do your translation lookup here, using whatever method you require
var imageSource = ImageSource.FromResource(Source, gtkAsm);
return imageSource;
}
}
}