Link Search Menu Expand Document

Embedded Image Extension

This markup extension adds built-in resources to place images directly into the shared project.


Table of contents

  1. Using Embedded Images Video

Using Embedded Images Video



Using Embedded Images Code Example

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace XF_MonettelliUIKIT.MarkupExtension
{

  // You exclude the 'Extension' suffix when using in Xaml markup
  [ContentProperty("Source")]
  public class EmbeddedImageExtension : 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(EmbeddedImageExtension).GetTypeInfo().Assembly);

      return imageSource;
    }
  }

}