How to refresh my Image Control after Captured Image in MVVM Light


  • Hi every One , 

    I am facing an Issue while binding the Image from My MVVM Model with Two way Binding . My Task is to Load the Image Initially with Default Image then i can capture a Image through My Tab. soon after that i need to update my Image from previous one to Newly captured Image . for that its not getting Refreshed .

    • I am able to load the default Image through my code .but not able to Refresh . i have feeling it could be because my tapped event also . which is getting called before my command method in ViewModel .

    private void captureButton_Tapped(object sender, TappedRoutedEventArgs e)        {            CustomerImage.Source = ((CustomerContactViewModel)this.DataContext).ContactImage;        }

    My xaml code is something like -


    <Border BorderThickness="1" BorderBrush="Gray">
                            <Image x:Name="CustomerImage" HorizontalAlignment="Right" Source="{Binding ContactImage,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />

    My C# code is ->

      private async void CaptureImage()        {            CameraCaptureUI dialog = new CameraCaptureUI();            Size aspectRatio = new Size(16, 9);            dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;            StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);            if (file != null)            {                BitmapImage bitmapImage = new BitmapImage();                using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))                {                    bitmapImage.SetSource(fileStream);                }                CustomerContact.cntthumbpath =  file.Path;                ImagePath = string.Empty;                ImagePath = file.Path;                ContactImage = new BitmapImage { UriSource = new Uri(string.Format(ImagePath)) };            }            else            {                                                //    //rootPage.NotifyUser("No photo captured.", NotifyType.StatusMessage);            }                   }

    Where Contact Images has Property ->

      private BitmapImage _Image;
            public BitmapImage ContactImage
                get { return _Image; }
                set { _Image = value; 

    Please let me know if any one have Idea how i can get over with this . 

    Regards Shivam

    Tuesday, March 18, 2014 11:20 AM

All replies

  • From the partial information you provide it looks like when you set the Image's source directly in your Tapped event you override the data binding. Instead set the Image to the ContactImage property so the binding will pick it up from there.


    Tuesday, March 18, 2014 11:33 PM
  • Thanks Rob ,
    I tried that way also , then also its showing the same Issue .

    Wednesday, March 19, 2014 1:35 PM
  • Can you share a minimal sample demonstrating the problem to your OneDrive? It is hard to guess what you are doing from a partial code snippet.
    Wednesday, March 19, 2014 2:13 PM