title: Loading FFImageLoading SVG into ImageButton Source from code?
body: <p>This <a href="https://stackoverflow.com/questions/49819295/ffimageloading-load-into-an-imagebutton">post</a> shows how to make SvgCachedImage act like a button. However, how to load SvgCachedImage into XamarinForm's ImageButton Source ? </p>
  
  <p>My non-working code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
               xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
               xmlns:local="clr-namespace:SharedSvgSample"
               x:Class="SharedSvgSample.MainPage"
               xmlns:ffimageloadingsvg="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms"&gt;
      &lt;StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"&gt;
          &lt;ImageButton
              x:Name="myButton"
              HeightRequest="200"
              Clicked="myButton_Clicked"
              WidthRequest="200" /&gt;
      &lt;/StackLayout&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p>Code-behind:</p>
  
  <pre><code>using FFImageLoading.Svg.Forms;
  using System;
  using Xamarin.Forms;
  
  namespace SharedSvgSample
  {
      public partial class MainPage : ContentPage
      {
          private bool _myButtonValue;
          private SvgImageSource _visibilityOn = null;
          private SvgImageSource _visibilityOff = null;
  
          public MainPage()
          {
              InitializeComponent();
              _visibilityOn = SvgImageSource.FromResource("SharedSvgSample.Resources.visibility_on.svg");
              _visibilityOn.VectorHeight = 100;
              _visibilityOn.VectorWidth = 100;
  
              _visibilityOff = SvgImageSource.FromResource("SharedSvgSample.Resources.visibility_off.svg");
              _visibilityOff.VectorHeight = 100;
              _visibilityOff.VectorWidth = 100;
  
              myButton.Source = _visibilityOff;   
          }
  
          private void myButton_Clicked(object sender, EventArgs e)
          {
              _myButtonValue = !_myButtonValue;
              myButton.Source = _myButtonValue ? _visibilityOn.ImageSource : _visibilityOff.ImageSource;
          }
      }
  }
  </code></pre>