This question is locked. New answers and comments are not allowed.
Essentially I'm using the InsertFragment to insert some premade spans with annotations into the document. One of the requirements is to be able to insert the annotations around text, which is why I'm not just using the Insert function. Later on, I will also be inserting custom controls with Annotations around them. End goal is to use the document, saved in a database, as a template for displaying dynamic data.
The issue I'm running into is that when I use the InsertFragment function the first time, it works great. When I call it a second time somewhere else in the document, it acts differently. These are two different button clicks on the menu to call the event handler which inserts into the document.
On the first insert, here is a part of the exported xaml:
The original text was "This is the first sentence." Then I inserted the fragment between 'the' and 'first'. This one turned out fine.
Here is theoutput from the exported xaml for the second insert:
As you can see, it adds a BaselineAlignment as well as several other properties to the inserted Spans that didn't exist in the first inserted fragment.
I get the same results if I use InsertFragment to insert a single span (no annotations) to the document. I am using the out of the box RadRichTextBox control with the context menu and RadRichTextBoxRibbonUI. I added an element to the ribbon which calls an event handler that creates a document, adds the section, paragraph, and spans, and then calls InsertFragment on the main document.
Please see the following source for the backing class:
Any ideas on what may be causing the second call to btnInsertAMSLabel_Click to insert the fragment differently?
Thanks,
Tyson
The issue I'm running into is that when I use the InsertFragment function the first time, it works great. When I call it a second time somewhere else in the document, it acts differently. These are two different button clicks on the menu to call the event handler which inserts into the document.
On the first insert, here is a part of the exported xaml:
<
t:Span
FontFamily
=
"Arial"
FontSize
=
"26.67"
FontWeight
=
"Bold"
Text
=
"This is the "
/>
<
t:Span
FontFamily
=
"Arial"
FontSize
=
"26.67"
FontStyle
=
"Normal"
FontWeight
=
"Bold"
ForeColor
=
"#FF000000"
HighlightColor
=
"#00FFFFFF"
Strikethrough
=
"False"
Text
=
"Ams Field: "
/>
<
custom1:AMSBindableFieldRangeStart
AMSFieldName
=
"AMS_FIELD_0"
AnnotationID
=
"1"
Name
=
"AMSBoundField_0"
/>
<
t:Span
FontFamily
=
"Arial"
FontSize
=
"26.67"
FontStyle
=
"Normal"
FontWeight
=
"Bold"
ForeColor
=
"#FF000000"
HighlightColor
=
"#00FFFFFF"
Strikethrough
=
"False"
Text
=
"AMS_FIELD_0"
UnderlineDecoration
=
"Wave"
/>
<
custom1:AMSBindableFieldRangeEnd
AnnotationID
=
"1"
/>
<
t:Span
FontFamily
=
"Arial"
FontSize
=
"26.67"
FontWeight
=
"Bold"
Text
=
" first sentence. This is the "
/>
The original text was "This is the first sentence." Then I inserted the fragment between 'the' and 'first'. This one turned out fine.
Here is theoutput from the exported xaml for the second insert:
<
t:Span
FontFamily
=
"Arial"
FontSize
=
"26.67"
FontWeight
=
"Bold"
Text
=
" first sentence. This is the "
/>
<
t:Span
BaselineAlignment
=
"Baseline"
FontFamily
=
"Arial"
FontSize
=
"16"
FontStyle
=
"Normal"
FontWeight
=
"Bold"
ForeColor
=
"#FF000000"
HighlightColor
=
"#00FFFFFF"
Strikethrough
=
"False"
Text
=
"Ams Field: "
ThemeForeColor
=
"none"
ThemeUnderlineColor
=
"none"
UnderlineColor
=
"#FF000000"
UnderlineDecoration
=
"None"
/>
<
custom1:AMSBindableFieldRangeStart
AMSFieldName
=
"AMS_FIELD_1"
AnnotationID
=
"2"
Name
=
"AMSBoundField_1"
/>
<
t:Span
BaselineAlignment
=
"Baseline"
FontFamily
=
"Arial"
FontSize
=
"16"
FontStyle
=
"Normal"
FontWeight
=
"Bold"
ForeColor
=
"#FF000000"
HighlightColor
=
"#00FFFFFF"
Strikethrough
=
"False"
Text
=
"AMS_FIELD_1"
ThemeForeColor
=
"none"
ThemeUnderlineColor
=
"none"
UnderlineColor
=
"#FF000000"
UnderlineDecoration
=
"Wave"
/>
<
custom1:AMSBindableFieldRangeEnd
AnnotationID
=
"2"
/>
<
t:Span
FontFamily
=
"Arial"
FontSize
=
"26.67"
FontWeight
=
"Bold"
Text
=
" second sentence."
/>
As you can see, it adds a BaselineAlignment as well as several other properties to the inserted Spans that didn't exist in the first inserted fragment.
I get the same results if I use InsertFragment to insert a single span (no annotations) to the document. I am using the out of the box RadRichTextBox control with the context menu and RadRichTextBoxRibbonUI. I added an element to the ribbon which calls an event handler that creates a document, adds the section, paragraph, and spans, and then calls InsertFragment on the main document.
Please see the following source for the backing class:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
using
Telerik.Windows.Documents.Model;
using
Telerik.Windows.Documents;
using
Telerik.Windows.Controls;
using
SLDetailConfigurationManager.Utils;
using
Telerik.Windows.Documents.UI.TextDecorations.DecorationProviders;
using
Telerik.Windows.Documents.Model.Styles;
namespace
SLDetailConfigurationManager {
public
partial
class
MainPage : UserControl {
private
static
int
_controlId = 0;
public
MainPage() {
InitializeComponent();
}
private
void
ApplyExistingStyleToSpan(
ref
Span span) {
span.CopyPropertiesFromStyle(rtbMain.CurrentEditingStyle);
span.FontFamily = rtbMain.CurrentEditingStyle.SpanProperties.FontFamily;
span.FontSize = rtbMain.CurrentEditingStyle.SpanProperties.FontSize;
span.FontStyle = rtbMain.CurrentEditingStyle.SpanProperties.FontStyle;
span.FontWeight = rtbMain.CurrentEditingStyle.SpanProperties.FontWeight;
span.ForeColor = rtbMain.CurrentEditingStyle.SpanProperties.ForeColor;
span.HighlightColor = rtbMain.CurrentEditingStyle.SpanProperties.HighlightColor;
span.Strikethrough = rtbMain.CurrentEditingStyle.SpanProperties.Strikethrough;
}
private
void
btnInsertAMSLabel_Click(
object
sender, RoutedEventArgs e) {
int
controlId = _controlId++;
RadDocument document =
new
RadDocument();
Section section =
new
Section();
Paragraph paragraph =
new
Paragraph();
Span label =
new
Span();
Span bound =
new
Span();
label.Text =
"Ams Field: "
;
ApplyExistingStyleToSpan(
ref
label);
AMSBindableFieldRangeStart start =
new
AMSBindableFieldRangeStart(
"AMSBoundField_"
+ controlId.ToString(),
"AMS_FIELD_"
+ controlId.ToString());
AMSBindableFieldRangeEnd end =
new
AMSBindableFieldRangeEnd();
end.PairWithStart(start);
bound.Text =
"AMS_FIELD_"
+ controlId.ToString();
ApplyExistingStyleToSpan(
ref
bound);
bound.UnderlineDecoration = UnderlineTypes.Wave;
paragraph.Inlines.Add(label);
paragraph.Inlines.Add(start);
paragraph.Inlines.Add(bound);
paragraph.Inlines.Add(end);
section.Blocks.Add(paragraph);
document.Sections.Add(section);
document.MeasureAndArrangeInDefaultSize();
document.Selection.SelectAll();
DocumentFragment frag = document.Selection.CopySelectedDocumentElements();
rtbMain.InsertFragment(frag);
rtbMain.Document.MeasureAndArrangeInDefaultSize();
}
}
}
Any ideas on what may be causing the second call to btnInsertAMSLabel_Click to insert the fragment differently?
Thanks,
Tyson