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

Linked style not working.

3 Answers 95 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Ruslan
Top achievements
Rank 1
Ruslan asked on 30 Oct 2017, 03:25 PM

Hello.

We are currently testing the RadRichTextBox control and due to our specific business needs we cannot use the ribbon UI so we are applying styles programmatically.

We are using the sample code from the documentation which describes how to apply a linked style however it does not work in our case - only the paragraph style is applied but the character one is ignored.

Our environment is VS 2017.

.NET Framework 4.6.2. (tried with 4.5 but got the same result).

Here is the code:

StyleDefinition linkedParagraphStyle = new StyleDefinition();
                linkedParagraphStyle.Type = StyleType.Paragraph;
                linkedParagraphStyle.ParagraphProperties.Background = Colors.Yellow;
                linkedParagraphStyle.DisplayName = "linkedParagraphStyle";
                linkedParagraphStyle.Name = "linkedParagraphStyle";

                StyleDefinition linkedCharStyle = new StyleDefinition();
                linkedCharStyle.Type = StyleType.Character;
                linkedCharStyle.SpanProperties.FontWeight = FontWeights.Bold;
                linkedCharStyle.SpanProperties.FontFamily = new FontFamily("Times New Roman");
                linkedCharStyle.DisplayName = "linkedCharStyle";
                linkedCharStyle.Name = "linkedCharStyle";
                linkedParagraphStyle.LinkedStyle = linkedCharStyle;

                this.textBox.Document.StyleRepository.Add(linkedParagraphStyle);
                this.textBox.Document.StyleRepository.Add(linkedCharStyle);
                this.textBox.ChangeStyleName("linkedCharStyle");

 

No matter how we change the linking and the naming of the styles and linked properties it will not apply the character properties.

Any help would be greatly appreciated.

Regards,

R.F.

3 Answers, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 02 Nov 2017, 09:51 AM
Hello Ruslan,

The method is working as expected on my side, but it seems to me you are having different expectations. The expected behavior ChangeStyleName is:
  • First get the two linked Paragraph style and Character style using the supplied style name. It works with both the paragraph part or the character part names of the linked style. 
  • if text in multiple paragraphs is selected, only the Paragraph style is applied to all of the selected paragraphs (even partially selected ones)
  • if exactly one paragraph is selected, or nothing is selected, only the Paragraph style is applied to the current paragraphs
  • if only part of the text in a paragraph is selected, only the Character style is applied to the selected text.

What are you trying to achieve? We may be able to provide a solution.

Regards,
Boby
Progress Telerik
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.
0
Ruslan
Top achievements
Rank 1
answered on 02 Nov 2017, 02:54 PM

Hello Boby and thank you for the answer.

What we are trying to achieve is just to apply the same linked style which means paragraph and character properties to the whole text in the rad rich textbox meaning that we might have several paragraphs.

Regards,

R.F.

0
Boby
Telerik team
answered on 07 Nov 2017, 06:34 AM
Hello Ruslan,

To achieve this, you can set the SpanProperties part of the paragraph style. Thus, when the Paragraph style is applied, the character formatting will be identical to the case in which the Character style is applied:
StyleDefinition linkedParagraphStyle = new StyleDefinition();
linkedParagraphStyle.Type = StyleType.Paragraph;
linkedParagraphStyle.ParagraphProperties.Background = Colors.Yellow;
linkedParagraphStyle.SpanProperties.FontWeight = FontWeights.Bold;
linkedParagraphStyle.SpanProperties.FontFamily = new FontFamily("Times New Roman");
linkedParagraphStyle.DisplayName = "linkedParagraphStyle";
linkedParagraphStyle.Name = "linkedParagraphStyle";
StyleDefinition linkedCharStyle = new StyleDefinition();
linkedCharStyle.Type = StyleType.Character;
linkedCharStyle.SpanProperties.FontWeight = FontWeights.Bold;
linkedCharStyle.SpanProperties.FontFamily = new FontFamily("Times New Roman");
linkedCharStyle.DisplayName = "linkedCharStyle";
linkedCharStyle.Name = "linkedCharStyle";
linkedParagraphStyle.LinkedStyle = linkedCharStyle;
this.textBox.Document.StyleRepository.Add(linkedParagraphStyle);
this.textBox.Document.StyleRepository.Add(linkedCharStyle);
this.textBox.ChangeStyleName("linkedCharStyle");

I hope this would help.


Regards,
Boby
Progress Telerik
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
Ruslan
Top achievements
Rank 1
Answers by
Boby
Telerik team
Ruslan
Top achievements
Rank 1
Share this question
or