Binding Image using MVVM

4 posts, 0 answers
  1. cielo valdoz
    cielo valdoz avatar
    33 posts
    Member since:
    Dec 2009

    Posted 27 Mar 2012 Link to this post

    Hi,

    I would like to load images dynamically to the RadImageEditor but the image is not displaying.
    The image was passed from another module then it will convert into an image.

    <

     

     

    telerik:RadImageEditorUI Margin="0" Name="RadImageEditorUI1" Image="{Binding ImagePath, Converter={StaticResource ImageConverter}}" SaveCommand="{Binding SaveImageCommand}">

     



    CONVERTER:

    Namespace Converter
      
        Public Class ImagesConverter
            Implements IValueConverter
            Private Shared ImageFolder As String = "Images/"
            Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
                Dim img As New BitmapImage()
                Dim imageEditor As New RadImageEditor
      
                If Not value Is Nothing Then
                    'value = "EGS14272012143526640.png"
      
                    img.UriSource = New Uri(ImageFolder & value.ToString, UriKind.Relative)
      
                Else
                    Return Nothing
                End If
      
                Return img
            End Function
      
            Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
      
            End Function
        End Class
    End Namespace

    Can anyone help me?

    Thanks,
    Cielo
  2. Mike
    Admin
    Mike avatar
    640 posts

    Posted 30 Mar 2012 Link to this post

    Hi Cielo,

    We tested that Image property binding works as expected on the side of the ImageEditor. The problem should be related to image converter. When debugging your Silverlight application you can check the debug output window if there are any errors related to the binding.

    In this case we noticed that the return object of type BitmapImage and RadImageEditorUI expects RadBitmap for the property Image which might be the problem. You should create RadBitmap from the BitmapImage and return it instead. Let us know if the problem persists.

    All the best,
    Mike
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Muhammad
    Muhammad avatar
    6 posts
    Member since:
    Apr 2011

    Posted 14 May 2013 Link to this post

    can you please explain how can i do this convert bitmap to radbitmap

    thanks in advance.
  5. Ye
    Ye avatar
    25 posts
    Member since:
    Aug 2012

    Posted 15 May 2013 Link to this post

    byte[] contents;
    
     IImageFormatProvider importer = ImageFormatProviderManager.GetFormatProviderByExtension(formatExtension);
                    if (importer != null)
                    {
                        this.radBitMap = importer.Import(contents);
                        return true;
                    }
    here is an example that use telerik's format provider to convert byte arrays to radBitMap.

Back to Top