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

how to force single span style for the whole paragraph

3 Answers 141 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 28 Mar 2017, 03:59 PM

Hi I have a paragraph style defined as

new StyleDefinition
{
   DisplayName = "Quotation 1",
   Name = "Quotation1",
   NextStyleName = "Normal",
   Type = StyleType.Paragraph,
   IsCustom = false,
   IsDefault = false,
   IsPrimary = true,
   UIPriority = 4,
   ParagraphProperties =
   {
     LineSpacing = 1.15,
     SpacingAfter = 56.0/3.0
   },
   SpanProperties =
   {
     FontFamily = new FontFamily("Calibri"),
     FontSize = 56 / 3.0,
     FontStyle = FontStyles.Normal,
     FontWeight = FontWeights.Bold,
     ForeColor = Color.FromRgb(193, 43, 103),
   }
};

I have a rad document with multiple paragraphs. If the paragraphs have a default styles I can apply my style to one of them and the document looks like expected. The chosen paragraph is pink and bold.

Unfortunately when the user of the application selects some words in the paragraph make them bold and then not bold again it creates a new span which has exectly the same properties including FontWeight Normal, but after I apply my style only the spans that weren't changed become pink bold while the changed remains Normal.

Is there a way to force span style to the whole paragraph?

3 Answers, 1 is accepted

Sort by
0
Mihail
Telerik team
answered on 31 Mar 2017, 03:58 PM
Hello Daniel,

I will try to explain in more details what is happening with the font-weight property of the span.

When the paragraph has a default style and no other styling properties are applied the span will have only default properties. However, once the user set bold as font-weight it sets it as a local property of the span. This means that no further evaluation will be triggered for this style property. This is applicable when the user sets the already bolded text to normal. The normal font-weight will be set as local style property and no further evaluation will be triggered for this style property.

I am afraid that there is no out of the box way to force the span to take the bold property from your paragraph style. The only possible way for you is to clear the font-weight property of the span before applying your paragraph style.
In order to achieve this, you should subscribe to the CommandExecuting event of the RadRichTextBox control and when the ChangeStyleNameCommand is executed to clear the span desired properties. Here is of how this could be done:
private void MainDemoControl_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
    ChangeStyleNameCommand changeStyleNameCommand = e.Command as ChangeStyleNameCommand;
    if(changeStyleNameCommand != null)
    {
        // clear the span desired local properties.
    }
}

I hope this information answers your question.

Regards,
Mihail
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Daniel
Top achievements
Rank 1
answered on 31 Mar 2017, 04:14 PM

Hi Mihail,

I did it in the similar way. And I added ClearAllFormatting() before ChangeStyleName, and it works when I have a selection. When I have no selection ChangeStyleName applies the style to the paragraph where the carriage is (which is correct) but the ClearAllFormatting doesn't work without selection.

Anyway this is just a workaround for lack of functionality from Word where when you are toggling to the state from the style, you are actually clearing the property.

0
Mihail
Telerik team
answered on 05 Apr 2017, 10:19 AM
Hello Daniel,

I agree that this is a missing functionality in comparison to MS Word. That is why I have logged a new feature request item in our feedback portal. Here is a link if you would like to follow the item: Implement clearing of span local property when applying a new value which is equal to the default value

Regards,
Mihail
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
RichTextBox
Asked by
Daniel
Top achievements
Rank 1
Answers by
Mihail
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or