Hi,
I am trying to remove some Document Element as Paragraph, Table, Images from section under RadRichTextBox .
But I want to implement the functionality which allow to add and remove the Document element on button click event.
Suppose I want to remove table from Section so Table having collection of Rows, Row having collection of Cells, Cell having collection of DocumentElement.
When I am get table from section and store it in local dictionary then table is come but not its inner collection like rows collection, cells collection (ie empty collection come), to solve this problem I have taken this values in my another collection.
But after got all the inner collection value I am trying to remove the DocumentElement from section it throws an exception and If I try to remove this DocuemntElement without getting his inner collection values then it removes normally.
reference code If I remove all comments then code thrown an error and with comment it run normally
Telerik.Windows.Documents.Model.Paragraph NextPara;
try
{
Telerik.Windows.Documents.Model.Span spanbox = editor.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan;
if
(spanbox.FontWeight==FontWeights.Bold && spanbox.ForeColor==Colors.Aqua)
{
Telerik.Windows.Documents.Model.Section currsect = editor.Document.CaretPosition.GetCurrentSectionBox().AssociatedSection;
Telerik.Windows.Documents.Model.Span currspan = editor.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan;
bool
check = editor.Document.CaretPosition.MoveToNextInline();
bool
c=editor.Document.CaretPosition.MoveToNextInline();
bool
c1=editor.Document.CaretPosition.MoveToNextInline();
var documentelement = editor.Document.CaretPosition.GetCurrentParagraphBox();
if
(documentelement !=
null
&& documentelement.GetType() ==
typeof
(Telerik.Windows.Documents.Layout.ParagraphLayoutBox))
{
Telerik.Windows.Documents.Model.Paragraph para = documentelement.AssociatedParagraph;
spanbox.Tag = Guid.NewGuid().ToString();
string
spantext = (para.Inlines.FirstOrDefault()
as
Telerik.Windows.Documents.Model.Span).Text;
if
(!
string
.IsNullOrEmpty(spantext) && spantext ==
"[@["
)
{
NextPara = para.NextSibling
as
Telerik.Windows.Documents.Model.Paragraph;
//var DocEle = new DocumentElementCollection(para);
//foreach (var item in para.Children)
//{
// DocEle.Add(item);
//}
currsect.Children.Remove(para);
//DocumentEleCollection.Add(DocEle);
while
(NextPara !=
null
)
{
if
(NextPara !=
null
&& (NextPara.Inlines.FirstOrDefault()
as
Telerik.Windows.Documents.Model.Span).Text ==
"]@]"
)
{
//var DocEle2 = new DocumentElementCollection(NextPara);
//foreach (var item in NextPara.Children)
//{
// DocEle2.Add(item);
//}
currsect.Children.Remove(NextPara);
//DocumentEleCollection.Add(DocEle2);
break
;
}
//var DocEle1 = new DocumentElementCollection(NextPara);
//foreach (var item in NextPara.Children)
//{
// DocEle1.Add(item);
//}
currsect.Children.Remove(NextPara);
//DocumentEleCollection.Add(DocEle1);
NextPara = NextPara.NextSibling
as
Telerik.Windows.Documents.Model.Paragraph;
}
}
}
}
}
catch
(Exception ex)
{ }