For a proof of concept linked to my question described here (see my last post) I have begun experimenting with modifying a deserialized RadDocument prior to assigning it to the control. The idea behind this is to store links to external resources using the standard HyperlinkRangeStart-HyperLink-HyperlinkRangeStop concept and transforming those hyperlinks into custom controls hosted in InlineUIContainer objects.To test if this can work I've tried the following:
var doc = provider.Import(xml);
var hyperLinks = doc.EnumerateChildrenOfType<HyperlinkRangeStart>();
foreach (var link in hyperLinks)
{
var parent = link.Parent;
parent.Children.Remove(link);
InlineUIContainer container = new InlineUIContainer(new Button(), new Size(400, 300));
parent.Children.Add(container);
}
doc.History.Clear();
// BOOOM
doc.UpdateLayout();
This will crash in UpdateLayout or when I assign the document to a RadRichTextBox with the following exception:
InvalidOperationException "Stack Empty"
" at System.Collections.Generic.Stack`1.Pop()\r\n at Telerik.Windows.Documents.Layout.LayoutBox.UpdateFieldProperties(DocumentElement element, Stack`1 fieldStartsStack) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutBox.cs:line 541\r\n at Telerik.Windows.Documents.Layout.LayoutBox.UpdateFieldProperties(DocumentElement element, Stack`1 fieldStartsStack) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutBox.cs:line 524\r\n at Telerik.Windows.Documents.Layout.LayoutBox.UpdateFieldProperties(DocumentElement element, Stack`1 fieldStartsStack) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutBox.cs:line 524\r\n at Telerik.Windows.Documents.Layout.LayoutBox.UpdateFieldProperties(DocumentElement element) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutBox.cs:line 520\r\n at Telerik.Windows.Documents.Layout.DocumentLayoutBox.UpdateGlobalProperties() in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\DocumentLayoutBox.cs:line 276\r\n at Telerik.Windows.Documents.Layout.DocumentLayoutBox.MeasureOverride(SizeF availableSize) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\DocumentLayoutBox.cs:line 259\r\n at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutElement.cs:line 1473\r\n at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutElement.cs:line 1352\r\n at Telerik.Windows.Documents.Layout.ContextLayoutManager.UpdateLayout() in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\ContextLayoutManager.cs:line 360\r\n at Telerik.Windows.Documents.Layout.LayoutElement.UpdateLayout() in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutElement.cs:line 982\r\n at Telerik.Windows.Documents.Model.RadDocument.UpdateLayout() in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Model\\RadDocument.cs:line 706\r\n at Mindspace.DocumentEditors.RichTextDocumentEditor.<SetEditorContent>b__3() in C:\\Users\\oliver\\Projects\\Mindspace\\SilverlightClient\\DocumentEditors\\RichTextDocumentEditor.cs:line 296"
var doc = provider.Import(xml);
var hyperLinks = doc.EnumerateChildrenOfType<HyperlinkRangeStart>();
foreach (var link in hyperLinks)
{
var parent = link.Parent;
parent.Children.Remove(link);
InlineUIContainer container = new InlineUIContainer(new Button(), new Size(400, 300));
parent.Children.Add(container);
}
doc.History.Clear();
// BOOOM
doc.UpdateLayout();
InvalidOperationException "Stack Empty"
" at System.Collections.Generic.Stack`1.Pop()\r\n at Telerik.Windows.Documents.Layout.LayoutBox.UpdateFieldProperties(DocumentElement element, Stack`1 fieldStartsStack) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutBox.cs:line 541\r\n at Telerik.Windows.Documents.Layout.LayoutBox.UpdateFieldProperties(DocumentElement element, Stack`1 fieldStartsStack) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutBox.cs:line 524\r\n at Telerik.Windows.Documents.Layout.LayoutBox.UpdateFieldProperties(DocumentElement element, Stack`1 fieldStartsStack) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutBox.cs:line 524\r\n at Telerik.Windows.Documents.Layout.LayoutBox.UpdateFieldProperties(DocumentElement element) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutBox.cs:line 520\r\n at Telerik.Windows.Documents.Layout.DocumentLayoutBox.UpdateGlobalProperties() in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\DocumentLayoutBox.cs:line 276\r\n at Telerik.Windows.Documents.Layout.DocumentLayoutBox.MeasureOverride(SizeF availableSize) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\DocumentLayoutBox.cs:line 259\r\n at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutElement.cs:line 1473\r\n at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize) in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutElement.cs:line 1352\r\n at Telerik.Windows.Documents.Layout.ContextLayoutManager.UpdateLayout() in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\ContextLayoutManager.cs:line 360\r\n at Telerik.Windows.Documents.Layout.LayoutElement.UpdateLayout() in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Layout\\LayoutElement.cs:line 982\r\n at Telerik.Windows.Documents.Model.RadDocument.UpdateLayout() in c:\\TB\\101\\WPF_Scrum\\Release_WPF_40\\Sources\\Development\\Documents\\Model\\RadDocument.cs:line 706\r\n at Mindspace.DocumentEditors.RichTextDocumentEditor.<SetEditorContent>b__3() in C:\\Users\\oliver\\Projects\\Mindspace\\SilverlightClient\\DocumentEditors\\RichTextDocumentEditor.cs:line 296"