Hello,
I'm showing a collection of text annotations using RichTextBox inside a ListBox. These annotation have an IsEnabled Property. When this property is set to true I'd like to Striketrough the text showed. As we are replacing an old system, many annotations come from data store in plain text, new ones, generated using a RadRichTextBox, I've created a custom DataProvider:
That works aparently fine, but using ToggleStrikethrough I'm not sure that text is Striketrough or not when needed. How can I, by code, ensure that all text in RichTextBox is Strikethrough?
I'm showing a collection of text annotations using RichTextBox inside a ListBox. These annotation have an IsEnabled Property. When this property is set to true I'd like to Striketrough the text showed. As we are replacing an old system, many annotations come from data store in plain text, new ones, generated using a RadRichTextBox, I've created a custom DataProvider:
public
class
AnnotationDataProvider: DependencyObject
{
private
XamlDataProvider _xamlProvider;
private
TxtDataProvider _txtProvider;
public
RadRichTextBox RichTextBox
{
get
{
return
(RadRichTextBox)GetValue(RichTextBoxProperty); }
set
{ SetValue(RichTextBoxProperty, value); }
}
// Using a DependencyProperty as the backing store for RichTextBox. This enables animation, styling, binding, etc...
public
static
readonly
DependencyProperty RichTextBoxProperty =
DependencyProperty.Register(
"RichTextBox"
,
typeof
(RadRichTextBox),
typeof
(AnnotationDataProvider),
new
PropertyMetadata(OnUpdateRichTextBox));
public
AnnotationViewModel Annotation
{
get
{
return
(AnnotationViewModel)GetValue(AnnotationProperty); }
set
{ SetValue(AnnotationProperty, value); }
}
// Using a DependencyProperty as the backing store for Annotation. This enables animation, styling, binding, etc...
public
static
readonly
DependencyProperty AnnotationProperty =
DependencyProperty.Register(
"Annotation"
,
typeof
(AnnotationViewModel),
typeof
(AnnotationDataProvider),
new
PropertyMetadata(
null
, OnUpdateRichTextBox));
private
static
void
OnUpdateRichTextBox(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var provider = d
as
AnnotationDataProvider;
provider.SetDataProvider();
}
private
void
SetDataProvider()
{
if
(RichTextBox !=
null
&& Annotation !=
null
)
UpdateDocument();
}
void
OnSetupDocument(
object
sender, SetupDocumentEventArgs e)
{
e.Document.LineSpacingType = Telerik.Windows.Documents.Model.LineSpacingType.Auto;
e.Document.LineSpacing = 1;
(sender
as
DataProviderBase).SetupDocument -= OnSetupDocument;
}
private
void
UpdateDocument()
{
if
(Annotation.XamlText != ClinicalCourseExportConstants.EmptyXamlText)
UpdateXaml();
else
UpdateTxt();
if
(Annotation.IsDisabled)
{
RichTextBox.Document.Selection.SelectAll();
RichTextBox.ToggleStrikethrough();
RichTextBox.Document.Selection.Clear();
}
}
private
void
UpdateXaml()
{
if
(_xamlProvider ==
null
)
_xamlProvider =
new
XamlDataProvider { RichTextBox = RichTextBox };
_xamlProvider.SetupDocument += OnSetupDocument;
_xamlProvider.Xaml = Annotation.XamlText;
_xamlProvider.UpdateDocument();
}
private
void
UpdateTxt()
{
if
(_txtProvider ==
null
)
_txtProvider =
new
TxtDataProvider { RichTextBox = RichTextBox };
_txtProvider.SetupDocument += OnSetupDocument;
_txtProvider.Text = Annotation.PlainText;
_txtProvider.UpdateDocument();
}
That works aparently fine, but using ToggleStrikethrough I'm not sure that text is Striketrough or not when needed. How can I, by code, ensure that all text in RichTextBox is Strikethrough?