BitmapImageConverter problem or what??

4 posts, 2 answers
  1. Leos
    Leos avatar
    57 posts
    Member since:
    Jul 2010

    Posted 10 Aug 2011 Link to this post

    Hi,
    I have next code:
    <telerik:DataFormDataField Label="{Binding Photo, Source={StaticResource res}}">
      <telerik:DataFormDataField.ContentTemplate>
        <DataTemplate>
          <Image Source="{Binding Photo, Converter={StaticResource bic}, Mode=TwoWay}"/>
        </DataTemplate>
      </telerik:DataFormDataField.ContentTemplate>
    </telerik:DataFormDataField>
    where "bic" is Telerik BitmapImageConverter and Photo is byte[] (readed with WCF.RIA from server database)
    It is working fine,  JPEG image is correctly displayed.

    But when I replace "Image line"  with:
    <telerik:RadImageEditorUI Image="{Binding Photo, Converter={StaticResource bic}, Mode=TwoWay}" />

    I got some strange exception and application crashes (!):
    Message: Set property 'Telerik.Windows.Controls.RadImageEditorUI.Image' threw an exception.

    I did plan to use this component for display photos from database and loading or saving them to disk :(

    What is wrong?
    Leos
  2. Answer
    Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 10 Aug 2011 Link to this post

    Hi Leos,

    First of all, thank you for your interest in RadImageEditorUI.
    To your question:
    Unfortunately, with the current version of the control, you cannot bind the Image property of RadImageEditor or RadImageEditorUI directly, due to the fact that it is not a dependency property. However, you can create your own control encapsulating RadImageEditor or RadImageEditorUI and expose a dependency property that's suitable for your binding scenario. You can synchronize it manually in the appropriate events.
    We have scheduled this behavior for revision and will implement some way for binding the image in the service pack in mid-September.

    All the best,
    Iva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. DevCraft banner
  4. Leos
    Leos avatar
    57 posts
    Member since:
    Jul 2010

    Posted 10 Aug 2011 Link to this post

    Hello Iva,
    thanks for answer.

    What event use to synchronize your and my Image after opening/changing image in your component?  How to get some info that (your) image was changed?

    And two tips for you:
    - please add IsReadonly property
    This property, when binded (with converter) to RadDataForm  mode and readonly, allows display and save image to disk (if image displayed)  but disallows open or change image.  Now you have only Enabled property and this disables saving of displayed image.
    - add button for clear/delete image to have chance save "no image" to data source .

    Leos
  5. Answer
    Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 16 Aug 2011 Link to this post

    Hi Leos,

    You can use the CurrentImageChanged event of the ImageHistory object, which RadImageEditor keeps as a property. Here is an example of how this can be done:

    this.ImageEditorUI.ImageEditor.History.CurrentImageChanged += History_CurrentImageChanged;
    CurrentImageChanged is fired when the image currently viewed in the editor has changed, i.e. if a command has been executed on the image loaded in the editor or the image has been changed all together.
    Therefore, you have to perform the following check in the event handler:
    private bool hasImageBeenChanged;
    void History_CurrentImageChanged(object sender, EventArgs e)
    {
       ImageHistory history = (ImageHistory)sender;
       if (!history.CanRedo && !history.CanUndo)
       {
          hasImageBeenChanged = true;
       }
       else
       {
          hasImageBeenChanged = false;
       }
    }

    As for the other items on your list, we are considering adding an IsReadOnly property for the ServicePack in mid September.
    When it comes to the clear/delete button, you can easily add a button by modifying the template of the control and using the methods from RadImageEditor's API.

    Regards,
    Iva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top