This is a migrated thread and some comments may be shown as answers.

Clear Formatting button not removing some formatting.

1 Answer 70 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Veteran
Bob asked on 22 Feb 2016, 08:19 PM
The "Clear Formatting" button in the RichTextBox editor menu is not removing things like the strike-through style, or margin properties from text pasted in from Microsoft Word.  Is there a simple way to have it do that?  I noticed that the "Reset All" button in the Paragraph dialog does clear the formatting better.  Is there a way to trigger the "Reset All" option when the "Clear Formatting" button is clicked?  Thanks, Jim

1 Answer, 1 is accepted

Sort by
0
Svetoslav
Telerik team
answered on 25 Feb 2016, 04:11 PM
Hi Bob,

Thank you for contacting us.

I tried to reproduce the described behavior, but it seems to work as expected on my end. Please, find attached a sample video, which demonstrates the steps I performed and let me know if I am missing something.

Overall, if you want to use the behaviour of the Reset All button of the Paragraph Properties Dialog instead of the ClearAllFomrattingCommand, I would suggest you to remove ClearAllFormattingCommand from XAML code and create your own command on button click. Here is how the command looks like in XAML:
<telerik:RadRibbonButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding ClearAllFormattingCommand}" Size="Small" SmallImage="{telerik:IconResource IconRelativePath=16/ClearFormatting16.png,IconSources={StaticResource IconSources}}" telerik:ScreenTip.Title="Clear All Formatting"/>

The code snippet below demonstrates how to select a paragraph and clear all the formatting applied to it:
private void ClearAllFomratingButtonClick(object sender, RoutedEventArgs e)
{
    this.radRichTextBox.Document.CaretPosition.MoveToFirstPositionInParagraph();
    var startPosition = this.radRichTextBox.Document.CaretPosition;
    var endPosition = new DocumentPosition(startPosition);
    endPosition.MoveToLastPositionInParagraph();
 
    this.radRichTextBox.Document.Selection.AddSelectionStart(startPosition);
    this.radRichTextBox.Document.Selection.AddSelectionEnd(endPosition);
 
    this.radRichTextBox.ClearAllFormatting();
    this.radRichTextBox.ClearTabStops(); 
}

I hope this helps. Let me know how it goes.

Regards,
Svetoslav
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Bob
Top achievements
Rank 1
Veteran
Answers by
Svetoslav
Telerik team
Share this question
or