How can I Striketrough a document by code

2 posts, 0 answers
  1. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 08 Mar 2011 Link to this post


    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;
            private void SetDataProvider()
                if (RichTextBox != null && Annotation != null)
            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)
                if (Annotation.IsDisabled)
            private void UpdateXaml()
                if (_xamlProvider == null)
                    _xamlProvider = new XamlDataProvider { RichTextBox = RichTextBox };
                _xamlProvider.SetupDocument += OnSetupDocument;
                _xamlProvider.Xaml = Annotation.XamlText;
            private void UpdateTxt()
                if (_txtProvider == null)
                    _txtProvider = new TxtDataProvider { RichTextBox = RichTextBox };
                _txtProvider.SetupDocument += OnSetupDocument;
                _txtProvider.Text = Annotation.PlainText;

    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?
  2. Iva Toteva
    Iva Toteva avatar
    1319 posts

    Posted 12 Mar 2011 Link to this post

    Hi Daní,

    Please find attached a sample demo. Note that in the AnnotationDataProvider, you have to measure and arrange the document before being able to strike it through using RadRichTextBox's API.
    I have included the second rich text box in the project, so that the structure of the document is clear at all times.
    You can see how you can get if the current word/ whole document is stricken-through when pressing the buttons in the top right corner.
    If that does not answer your question you need anything else, do not hesitate to contact us again.

    Kind regards,
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. DevCraft R3 2016 release webinar banner
Back to Top