XamlText property (in my ViiewModel object) never is empty. Debugging the application I may observe the exception is thrown before XamlDataProvider tries to get XamlText property in its DataContext object. I've placed a break point at XamlText property get accessor. Firstly, exception is thrown and then debugger breaks on the XamlText property. This didn't occur before Q1 2011 release. Walking by the exception call stack I can see a Telerik.Windows.Documents.FormatProviders.DataProviderBase.RichTextBoxChangedCallback method call that originates a DataProviderBase.UpdateDocument call. As now XamlDataProviderBase is a control, it seems the RichTextBoxChangedCallback is called before OnApplyTemplate and control is trying to format Xaml property when is not bound yet.
As I mentioned previously, I'm using a RichTextBox in readonly mode inside a ListBox, I'm pasting the DataTemplate used for ListBox ItemTemplate, may this may help:
<
DataTemplate
x:Key
=
"AnnotationViewTemplate"
>
<
Border
BorderBrush
=
"Black"
BorderThickness
=
"0,0,0,2"
Padding
=
"0,0,0,5"
>
<
Grid
x:Name
=
"LayoutRoot"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
telerik:RadWrapPanel
Grid.Row
=
"0"
>
<
telerik:RadRibbonButton
VerticalAlignment
=
"Center"
Command
=
"{Binding Path=CopyCommand, ElementName=copyBehavior}"
telerik:ScreenTip.Title
=
"{Binding Path=CopyAnnotationTitle, Source={StaticResource Strings}}"
telerik:ScreenTip.Description
=
"{Binding Path=CopyAnnotationDescription, Source={StaticResource Strings}}"
CollapseToSmall
=
"WhenGroupIsMedium"
Size
=
"Medium"
SmallImage
=
"/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/copy.png"
FontSize
=
"9.333"
Margin
=
"0,0,5,0"
/>
<
StackPanel
Margin
=
"5,5,15,5"
Orientation
=
"Horizontal"
Visibility
=
"{Binding FormattedDate, Converter={StaticResource TextLengthToVisibilityConverter}}"
>
<
TextBlock
TextWrapping
=
"Wrap"
Text
=
"{Binding Path=AnnotationDateLabel, Source={StaticResource Strings}}"
Margin
=
"0,0,6,0"
Style
=
"{StaticResource LabelTextStyle}"
/>
<
TextBlock
Style
=
"{StaticResource DataHighlightTextBlock}"
Text
=
"{Binding FormattedDate}"
telerik:ScreenTip.Title
=
"{Binding Path=AnnotationDateLabel, Source={StaticResource Strings}}"
telerik:ScreenTip.Description
=
"{Binding FormattedDate}"
/>
</
StackPanel
>
<
StackPanel
Margin
=
"5,5,15,5"
Orientation
=
"Horizontal"
Visibility
=
"{Binding Responsible, Converter={StaticResource TextLengthToVisibilityConverter}}"
>
<
TextBlock
TextWrapping
=
"Wrap"
Text
=
"{Binding AnnotationResponsibleLabel, Source={StaticResource Strings}}"
Margin
=
"0,0,6,0"
Style
=
"{StaticResource LabelTextStyle}"
/>
<
TextBlock
Style
=
"{StaticResource DataHighlightTextBlock}"
Text
=
"{Binding Responsible}"
telerik:ScreenTip.Title
=
"{Binding AnnotationResponsibleLabel, Source={StaticResource Strings}}"
telerik:ScreenTip.Description
=
"{Binding Responsible}"
/>
</
StackPanel
>
<
StackPanel
Orientation
=
"Horizontal"
Margin
=
"5"
Visibility
=
"{Binding SpecialityDescription, Converter={StaticResource TextLengthToVisibilityConverter}}"
>
<
TextBlock
TextWrapping
=
"Wrap"
Text
=
"{Binding AnnotationSpecialityLabel, Source={StaticResource Strings}}"
Margin
=
"0,0,6,0"
Style
=
"{StaticResource LabelTextStyle}"
/>
<
TextBlock
Style
=
"{StaticResource DataTextStyleWordEllipses}"
Text
=
"{Binding SpecialityDescription}"
telerik:ScreenTip.Title
=
"{Binding Path=AnnotationSpecialityTitle, Source={StaticResource Strings}}"
telerik:ScreenTip.Description
=
"{Binding SpecialityDescription}"
/>
</
StackPanel
>
<
StackPanel
Orientation
=
"Horizontal"
Margin
=
"5,5,15,5"
Visibility
=
"{Binding Episode, Converter={StaticResource TextLengthToVisibilityConverter}}"
>
<
TextBlock
TextWrapping
=
"Wrap"
Text
=
"{Binding Path=AnnotationEpisodeLabel, Source={StaticResource Strings}}"
Margin
=
"0,0,6,0"
Style
=
"{StaticResource LabelTextStyle}"
/>
<
TextBlock
Style
=
"{StaticResource DataHighlightTextBlock}"
Text
=
"{Binding Episode}"
telerik:ScreenTip.Title
=
"{Binding Path=AnnotationEpisodeLabel, Source={StaticResource Strings}}"
telerik:ScreenTip.Description
=
"{Binding Episode}"
/>
</
StackPanel
>
<
StackPanel
Orientation
=
"Horizontal"
Margin
=
"5,5,15,5"
Visibility
=
"{Binding TreatmentUnityDescription, Converter={StaticResource TextLengthToVisibilityConverter}}"
>
<
TextBlock
TextWrapping
=
"Wrap"
Text
=
"{Binding AnnotationTreatmentUnityDescriptionLabel, Source={StaticResource Strings}}"
Margin
=
"0,0,6,0"
Style
=
"{StaticResource LabelTextStyle}"
/>
<
TextBlock
Style
=
"{StaticResource DataTextStyleWordEllipses}"
Text
=
"{Binding TreatmentUnityDescription}"
telerik:ScreenTip.Title
=
"{Binding Path=TreatmentUnityTitle, Source={StaticResource Strings}}"
telerik:ScreenTip.Description
=
"{Binding TreatmentUnityDescription}"
/>
</
StackPanel
>
<
StackPanel
Orientation
=
"Horizontal"
Margin
=
"5"
Visibility
=
"{Binding ServiceText, Converter={StaticResource TextLengthToVisibilityConverter}}"
>
<
TextBlock
TextWrapping
=
"Wrap"
Margin
=
"0,0,6,0"
Text
=
"{Binding Path=AnnotationServiceLabel, Source={StaticResource Strings}}"
Style
=
"{StaticResource LabelTextStyle}"
/>
<
TextBlock
Style
=
"{StaticResource DataHighlightTextBlock}"
Text
=
"{Binding ServiceText}"
telerik:ScreenTip.Title
=
"{Binding Path=AnnotationServiceLabel, Source={StaticResource Strings}}"
telerik:ScreenTip.Description
=
"{Binding ServiceText}"
/>
</
StackPanel
>
<
StackPanel
Orientation
=
"Horizontal"
Margin
=
"5"
Visibility
=
"{Binding Path=IsDisabled, Converter={StaticResource BooleanToVisibilityConverter}}"
>
<
TextBlock
TextWrapping
=
"Wrap"
Margin
=
"0,0,6,0"
Text
=
"{Binding Path=AnnotationDisablingDateLabel, Source={StaticResource Strings}}"
Style
=
"{StaticResource LabelTextStyle}"
/>
<
TextBlock
Style
=
"{StaticResource DataHighlightTextBlock}"
Text
=
"{Binding FormattedDisablingDate}"
telerik:ScreenTip.Title
=
"{Binding Path=AnnotationDisablingDateLabel, Source={StaticResource Strings}}"
telerik:ScreenTip.Description
=
"{Binding FormattedDisablingDate}"
/>
</
StackPanel
>
</
telerik:RadWrapPanel
>
<
telerik:RadRichTextBox
BorderThickness
=
"0"
Grid.Row
=
"1"
IsSelectionMiniToolBarEnabled
=
"False"
HorizontalContentAlignment
=
"Stretch"
IsContextMenuEnabled
=
"True"
DocumentInheritsDefaultStyleSettings
=
"True"
FontFamily
=
"Verdana"
FontSize
=
"12"
IsSpellCheckingEnabled
=
"False"
Width
=
"Auto"
VerticalScrollBarVisibility
=
"Disabled"
x:Name
=
"RichTextBox"
IsReadOnly
=
"True"
HorizontalScrollBarVisibility
=
"Disabled"
>
<
i:Interaction.Behaviors
>
<
localBehaviors:RichTextBoxCopyBehavior
x:Name
=
"copyBehavior"
/>
</
i:Interaction.Behaviors
>
</
telerik:RadRichTextBox
>
<
telerikXaml:XamlDataProvider
Grid.Row
=
"1"
Xaml
=
"{Binding Path=XamlText, Mode=TwoWay}"
RichTextBox
=
"{Binding ElementName=RichTextBox}"
ccBehaviors:DefaultLineSpacingBehavior.DefaultLineSpacing
=
"1"
/>
</
Grid
>
</
Border
>
</
DataTemplate
>