How to refer to Embedded Resources from XAML?

前端 未结 4 713
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 16:52

I have several images that i want to be Embedded into the exe.

When i set the Build Action to Embedded Resource I get through out t

4条回答
  •  遥遥无期
    2020-12-03 17:33

    Just for those using xamarin forms and bump into this question, this can be done by creating a custom xaml markup extension explained here:

    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=windows

    in the "Embedded Images"->"Using XAML" section

    Citation of custom extension

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

    citation of how to use

    
    
     
       
       
     
    
    

提交回复
热议问题