Created
May 30, 2019 02:00
-
-
Save aimore/5b2048a1f2c29f75726567dbb53b8728 to your computer and use it in GitHub Desktop.
Image source extension xamarin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ContentProperty(nameof(Source))] | |
public class ImageResourceExtension : IMarkupExtension | |
{ | |
public string Source { get; set; } | |
public object ProvideValue(IServiceProvider serviceProvider) | |
{ | |
if (Source == null) | |
{ | |
return null; | |
} | |
// Do your translation lookup here, using whatever method you require | |
var imageSource = ImageSource.FromResource(Source, typeof(ImageResourceExtension).GetTypeInfo().Assembly); | |
return imageSource; | |
} | |
public static string ImageNameFromResource(string u) | |
{ | |
var assembly = typeof(App).GetTypeInfo().Assembly; | |
foreach (var res in assembly.GetManifestResourceNames()) | |
{ | |
// System.Diagnostics.Debug.WriteLine("found resource: " + res); | |
if (res.Contains(u)) | |
{ | |
return res; | |
} | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment