This is a migrated thread and some comments may be shown as answers.

[Solved] ImageInline not preserving UriSource

13 Answers 232 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Oliver
Top achievements
Rank 1
Oliver asked on 10 Apr 2011, 02:58 PM
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.

13 Answers, 1 is accepted

Sort by
0
Oliver
Top achievements
Rank 1
answered on 12 Apr 2011, 08:43 AM
I'd really appreciate some solution for this problem.
0
Iva Toteva
Telerik team
answered on 13 Apr 2011, 01:38 PM
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
0
Oliver
Top achievements
Rank 1
answered on 13 Apr 2011, 01:53 PM
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.
0
Iva Toteva
Telerik team
answered on 15 Apr 2011, 12:21 PM
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
0
Oliver
Top achievements
Rank 1
answered on 15 Apr 2011, 12:40 PM
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.
0
Iva Toteva
Telerik team
answered on 21 Apr 2011, 12:44 PM
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
0
Oliver
Top achievements
Rank 1
answered on 04 May 2011, 07:59 AM
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.
0
Iva Toteva
Telerik team
answered on 09 May 2011, 04:33 PM
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
0
Alois
Top achievements
Rank 1
answered on 02 Jul 2011, 02:40 PM
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
0
Rodel
Top achievements
Rank 1
answered on 22 Feb 2012, 12:38 AM
Hi All,

Has this issue been resolved with the latest release?
0
Iva Toteva
Telerik team
answered on 24 Feb 2012, 10:09 AM
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 >>
0
Rodel
Top achievements
Rank 1
answered on 20 Mar 2012, 10:32 PM
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
0
Iva Toteva
Telerik team
answered on 22 Mar 2012, 11:06 AM
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 >>
Tags
RichTextBox
Asked by
Oliver
Top achievements
Rank 1
Answers by
Oliver
Top achievements
Rank 1
Iva Toteva
Telerik team
Alois
Top achievements
Rank 1
Rodel
Top achievements
Rank 1
Share this question
or