This repository has been archived on 2020-12-20. You can view files and clone it, but cannot push or open issues or pull requests.
aurora-sharp-desktop/Aurora/Design/Extensions/ImageResourceExtension.cs

43 lines
1.2 KiB
C#

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);
}
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;
}
}
}