I have a XamRichTextEditor that I am using and I have recently gotten some weird errors when trying to manually refresh the value of my HtmlDocumentAdapter manually. I want my HtmlDocumentAdapter.Value to be equivalent to a custom Dependency Property on my custom control (that utilizes the XamRichTextEditor and HtmlDocumentAdapter, amoung other things).
The code fires in the XamRichTextEditor.Document.ContentChanged event. Here is some example code:
private void Document_ContentChanged(Object sender, DocumentContentChangedEventArgs e) { if (!this.htmlLostFocusTrigger && this.htmlAdapter != null) { try { this.htmlAdapter.RefreshValue(); this.Html = this.htmlAdapter.Value; this.htmlExp.UpdateSource(); } catch { } } }
When this.Html = this.htmlAdapter.Value; fires I get a weird exception and my UI completely blocks and freezes. After waiting a while I get a ContextSwitchDeadlock exception.
Note, this happens after I paste html then try to add some new content to the editor. Something is breaking. If I remove that line all seems to be fixed, but then my bindings work improperly.
Attached is the html I am pasting, my CS file, and my XAML theme for my custom control.
Hello Carson,
Thank you for posting!
I have been looking into your issue and have created a small sample application in order to test the scenario you have reported. In the sample application I have extracted the code related to the XamRichTextEditor from the two files you have provided and handled the ContentChanged event of the Document of the XamRichTextEditor.
Then in the handler of the event I have placed the code snippet, that you have mentioned and everything works as expected when the HTML is pasted and I try to add new content via typing.
I am attaching the sample application I have been testing with. As you are creating a custom control would you please modify the sample application with the functionality you are using so it reproduces the issue? This way I would be able to further investigate this matter for you.
Looking forward to hearing from you.
I cannot reproduce the error in the test project either, however I am getting a weird flickering when I type after pasting in the HTML. In the project I have attached the HTML. Render it then do a copy/paste and you should hopefully get the same issue. Maybe the flickering and my binding issue are the same problem, just my binding classes in our actual application have something that conflicts with the control?
Also, I do not get the same line spacing when I paste in the HTML in the test app as I do in my main app. I get the proper spacing in the test app but I get extra margins after each paragraph in my main app. I am unsure as to why.
Let me know if you have any insight.
Thanks.
I found the bug. IT was an internal error...
Thank you for the feedback. I am glad you have found a solution to your issue.