ImageInline not preserving UriSource

14 posts, 0 answers
  1. Oliver
    Oliver avatar
    36 posts
    Member since:
    Apr 2011

    Posted 10 Apr 2011 Link to this post

    I'm working on a fairly complex application utilizing the RadRichTextBox and I've run into an issue that's causing me major headache. In order to keep markup and images separate on our backend we are using ImageInline objects with UriSource in our documents. While that works fine at runtime, as soon as the the RadDocument is persisted using the XamlFormatProvider the UriSource gets discarded and replaced by inline image data using the RawData property.

    This is a major issue for us since we absolutely need to keep markup and external resources such as images separate in our backend. Is there any way to keep the XamlFormatProvider from doing this? IMO there should be a way since the HtmlFormatProvider is perfectly capable of doing that and my tests have shown that the RadDocument also loads documents containing ImageInline objects with UriSources just fine (modified the XamlMarkup at XML level for testing this).

    Any help would be greatly appreciated.
  2. Oliver
    Oliver avatar
    36 posts
    Member since:
    Apr 2011

    Posted 12 Apr 2011 Link to this post

    I'd really appreciate some solution for this problem.
  3. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 13 Apr 2011 Link to this post

    Hi Oliver,

    Unfortunately, you cannot achieve this behavior with XamlFormatProvider with the current version of the controls. We will consider providing XAML Export/Import settings, similar to the settings that HtmlFormatProvider has. As a possible workaround, you can postprocess the XAML after exporting with a simple XML parser.
    Your Telerik points have been updated in appreciation of the feature suggestion.

    Regards,
    Iva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Oliver
    Oliver avatar
    36 posts
    Member since:
    Apr 2011

    Posted 13 Apr 2011 Link to this post

    Any chance that feature makes into the upcoming SP release?

    Regarding the XML Post-Processing: we are already doing that. To explain a little how we work with the RadDocument consider the following steps:

    1. Listen for the RadRichTextBox.DocumentContentChanged event (which gets unfortunately triggered right after loading for documents post-processed using the steps outlined here - which is the second issue that plagues us)
    2. If the DocumentContentChanged was fired, mark the Document internally as modified and Save it when the user navigates to another Document.
    3. During Save, export the document content using the XamlFormatProvider
    4. Read the resulting Xaml into an XDocument and find all ImageInline nodes
    5. For each ImageInline that we find, check if it has an UriSource attribute, if it has one proceed to step 7
    6. If it has no UriSource attribute but a RawData attribute, decode the raw image data, encode the data as JPG, upload it to our backend and assign the ImageInline object an UriSource attribute pointing to our backend servers and finally strip the RawData attribute
    7. Serialize the modified XDocument to xml and upload it to our backend

    As you see, because of the XamlFormatProvider discards the UriSource attribute, we have to treat images in the document as new ones every time the document is saved. Sure we detect that those images are already present on the backend storage because we hash them prior to uploading but all this happens very very late in our persistence pipeline and most of the time for no reason since the document was not modified at all. And all this has another unfortunate side effect. The DocumentContentChanged is triggered directly after loading the XAML source using the XamlFormatProvider. Maybe because it is converting the UriSource data to RawData and triggering a false positive DocumentContentChanged event.
  5. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 15 Apr 2011 Link to this post

    Hi Oliver,

    We are already under code freeze for the service pack, as it is due any day now. Therefore, no changes can be included in it at this point.
    As for the DocumentContentChanged, it is triggered when you change the document in the rich text box. What you can do to avoid that is to listen to the DocumentContentChanged of the new document. This should do the trick:

    private void editor_DocumentContentChanged(object sender, EventArgs e)
    {
        // Mark the document as modified
    }
     
    private void editor_DocumentChanged(object sender, EventArgs e)
    {
        RadDocument document =  (sender as RadRichTextBox).Document;
        // Preprocess the document if needed
        document.DocumentContentChanged += editor_DocumentContentChanged;
    }

    All the best,
    Iva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Oliver
    Oliver avatar
    36 posts
    Member since:
    Apr 2011

    Posted 15 Apr 2011 Link to this post

    Thanks Iva. I've already tried that but DocumentContentChanged fires after the DocumentChanged event handler has been called. I suspect this is because the image data is loaded from UriSource async and then converted to RawData and this triggers the DocumentContentChanged event. Could you confirm this?

    This leaves me with a Document that is in modified state directly after loading with no way to detect this case.
  7. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 21 Apr 2011 Link to this post

    Hi Oliver,

    When you instantiate a RadRichTextBox, an empty document is assigned to it by default (if you have declared a document in XAML, that one is used). When you open a new Document, first DocumentChanged is fired and right after that DocumentContentChanged of the RichTextBox is fired. There is no processing when assigning the document to the RadRichTextBox.
    However, RadDocument also has a DocumentContentChanged event and that one is not fired unless actual changes in the document have been made. Therefore, the code from the snippet should provide a solution in your case. Maybe it was my naming of the handlers that mislead you, here is the revised code:

    private void radRichTextBoxEditor1_DocumentChanged(object sender, EventArgs e)
    {
        RadDocument document = (sender as RadRichTextBox).Document;
        foreach (var span in document.EnumerateChildrenOfType<Span>())
        {
            span.Text += "aaaa";
        }
        document.DocumentContentChanged += RadDocument_DocumentContentChanged;
        Debug.WriteLine("document changed");
    }
           
    private void RadDocument_DocumentContentChanged(object sender, EventArgs e)
    {
        Debug.WriteLine("doc: document content changed");
    }

    And in XAML:
    <telerik:RadRichTextBox Name="radRichTextBoxEditor1" Grid.Row="1" DocumentChanged="radRichTextBoxEditor1_DocumentChanged" /> <!-- No handler for DocumentContentChanged! -->

    Hope this helps.

    Regards,
    Iva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Oliver
    Oliver avatar
    36 posts
    Member since:
    Apr 2011

    Posted 04 May 2011 Link to this post

    No that doesn't help. Modifying a RadDocument in the way I have described leads to a document that fires the DocumentContentChanged event some time (100 to 1000ms) after being loaded. No matter wether you listen for DocumentContentChanged on the Editor or on the Editor's current Document. And this is clearly a bug.
  9. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 09 May 2011 Link to this post

    Hi Oliver,

    We have scheduled a revision of the events that are triggered when a new document is loaded in the RichTextBox.
    If the change is approved of, it will be included in the next official release - Q2, which is expected some time in mid-July.

    Greetings,
    Iva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Alois
    Alois avatar
    6 posts
    Member since:
    Feb 2011

    Posted 02 Jul 2011 Link to this post

    Hi,

    I experienced the same problem. My solution is to use the Loaded event instead of the DocumentChanged event to add my DocumentContentChanged method.

    Kind Regards
    Alois
  11. Rodel
    Rodel avatar
    4 posts
    Member since:
    Feb 2012

    Posted 21 Feb 2012 Link to this post

    Hi All,

    Has this issue been resolved with the latest release?
  12. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 24 Feb 2012 Link to this post

    Hi Rodel,

    If you are referring to the latest topic discussed in this forum - the way the DocumentContentChanged event is fired, the logic has been revised. Now DocumentContentChanged is not fired when a new document is opened and is only fired when changes are applied to the document in the editor.

    All the best,
    Iva Toteva
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  13. Rodel
    Rodel avatar
    4 posts
    Member since:
    Feb 2012

    Posted 20 Mar 2012 Link to this post

    Thanks Iva..

    My problem is similar to Oliver's issue. When I use the XamlFormatProvider for the Image the UriSource gets discarded and replaced by inline image data using the RawData property. The flow of our silverlight app is below:
    1. Retrieve the Xaml content from Database(which has UriSource)
    2. Use XamlFormat provider to display content on RichText control. At this point the UriSource gets discarded and replaced by RawData
    3. In some cases we allow users to edit the content so when it get's saved the RawData is persisted instead of the UriSource, which we don't want to happen.

    Best Regards,
    Rodel
  14. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 22 Mar 2012 Link to this post

    Hello Rodel,

    We are considering the implementation of Xaml Import and ExportSettings, similar to those of HtmlFormatProvider described here.
    However, if the users are inserting the pictures using the InsertPictureDialog, the UriSource of the images will not be set. Could you describe in greater detail the behavior you think will be appropriate when exporting and importing images? For example, would you be saving the images in another table in the database and using the UriSource to retrieve those images?

    Looking forward to your reply. 

    Regards,
    Iva Toteva
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top