title: Capturing and updating an image source using MVVM in Xamarin
body: <p>I'm trying to capture photo and display the captured image in Xamarin but changing the image source binding just doesn't seem to work. This seems really simple so I'm not quite sure where I'm going wrong.</p>
  
  <p><strong>MainPageViewModel.cs</strong></p>
  
  <pre><code>public class MainPageViewModel : ViewModelBase
  {
  
      private string _imageSource;
      public string ImageSource
      {
          get { return _imageSource; }
          set
          {
              _imageSource = value;
              SetProperty(ref _imageSource, value);
          }
      }
  
      public DelegateCommand TakePhotoCommand { get; private set; }
  
      public MainPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService)
          : base(navigationService)
      {
          Title = "Main Page";
  
          _dialogService = pageDialogService;
  
          TakePhotoCommand = new DelegateCommand(TakePhoto);
  
      }
  
  
      async void TakePhoto()
      {
  
          await CrossMedia.Current.Initialize();
  
          if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
          {
              await _dialogService.DisplayAlertAsync("No Camera", ":( No camera avaialble.", "OK");
  
              return;
          }
  
  
          var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
          {
              PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium,
              Directory = "Sample",
              Name = "test.jpg"
          });
  
          if (file == null)
              return;
  
          // This does get called ok
          ImageSource = file.Path;
  
      }
  }
  </code></pre>
  
  <p><strong>ViewModelBase.cs</strong></p>
  
  <pre><code>public class ViewModelBase : BindableBase, INavigationAware, IDestructible
  {
      protected INavigationService NavigationService { get; private set; }
  
      private string _title;
      public string Title
      {
          get { return _title; }
          set { SetProperty(ref _title, value); }
      }
  
      public ViewModelBase(INavigationService navigationService)
      {
          NavigationService = navigationService;
      }
  
      public virtual void OnNavigatedFrom(NavigationParameters parameters)
      {
  
      }
  
      public virtual void OnNavigatedTo(NavigationParameters parameters)
      {
  
      }
  
      public virtual void OnNavigatingTo(NavigationParameters parameters)
      {
  
      }
  
      public virtual void Destroy()
      {
  
      }
  }
  </code></pre>
  
  <p><strong>MainPage.xaml</strong></p>
  
  <pre><code>&lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
               xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
               x:Class="PhotoTesting.Views.MainPage"
               Title="{Binding Title}"&gt;
  
      &lt;StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"&gt;
          &lt;Image Source="{Binding ImageSource}" WidthRequest="200" HeightRequest="200" Aspect="AspectFill" /&gt;
          &lt;Button x:Name="CameraButton" Text="Take Photo" Command="{Binding TakePhotoCommand}" /&gt;
      &lt;/StackLayout&gt;
  
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p>I know the image capture bit is working ok, the problem just seems to be setting the <code>image.source</code> after the page has loaded.</p>