Linked style not working.

4 posts, 0 answers
  1. Ruslan
    Ruslan avatar
    2 posts
    Member since:
    Apr 2016

    Posted 30 Oct Link to this post

    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.

  2. Boby
    Admin
    Boby avatar
    639 posts

    Posted 02 Nov Link to this post

    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.
  3. Ruslan
    Ruslan avatar
    2 posts
    Member since:
    Apr 2016

    Posted 02 Nov in reply to Boby Link to this post

    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.

  4. Boby
    Admin
    Boby avatar
    639 posts

    Posted 07 Nov Link to this post

    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.
Back to Top