Stylesheets and Title

2 posts, 1 answers
  1. Axelle
    Axelle avatar
    13 posts
    Member since:
    Mar 2014

    Posted 03 Jun 2014 Link to this post

    Hello, 

    I'm trying to define a custom stylesheet for a RadRichTextbox with different level of titles.
    Basically, I'm looking to have "Part titles" that won't display as numbered but that will still "reset" the level of the subtitles 

    (Something like : 
    First part
    1. Chapter 1
    1.1 Part 1
    2. Chapter 2
    2.1 
    2.2
    Second part
    1. Another firstchapter
    1.1 

    etc... 

    This has to be defined through styles because this document are built by merging different parts. I think ParagraphProperties ListLevel and ListId attributes might be what I'm looking for, but I didn't figure it out just yet.

    Is there a detailed documentation of stylesheets in xaml, and the interaction between paragraphs and lists somewhere ? 

    Thanks a lot, 

    Axelle




  2. Answer
    Petya
    Admin
    Petya avatar
    975 posts

    Posted 06 Jun 2014 Link to this post

    Hello Axelle,

    The documentation regarding Stylesheets is located here and explains how to import/export a stylesheet.

    When it comes to creating a list, you can find the ListStyles documentation here. As you can see, each list level has its text (represented by its LevelText property and the {0}{1} etc. strings in the UI). In your case what you need to do is specify the first level in the style to be without text and each level after it to not include the most-outer enumeration. Please check the following code snippet on how you can define such list.
    ListStyle style = new ListStyle();
    style.StyleLink = "Style";
     
    ListLevelStyle level0 = new ListLevelStyle();
    level0.NumberingFormat = ListNumberingFormat.Decimal;
    level0.LevelText = " ";
    level0.Indent = 0;
    level0.StartingIndex = 1;
    style.Levels.Add(level0);
     
    for (int i = 1; i < ListStyle.ListLevels; ++i)
    {
        StringBuilder levelText = new StringBuilder();
        for (int j = 1; j < i + 1; ++j)
        {
            levelText.Append("{" + j + "}.");
        }
     
        style.Levels.Add(new ListLevelStyle()
        {
            StartingIndex = 1,
            NumberingFormat = ListNumberingFormat.Decimal,
            LevelText = levelText.ToString(),
            Indent = 24 + i * 24
        });
    }
     
    ListStyle newListStyle = this.radRichTextBox.Document.AddCustomListStyle(style);

    After that you need to make sure all Heading titles in your document are associated with an instance of this list style. For this purpose you can create a DocumentList and specify the ParagraphProperties.ListId and ListLevel properties of each Heading style.
    ListStyle newListStyle = this.radRichTextBox.Document.AddCustomListStyle(style);
    DocumentList documentList = new DocumentList(newListStyle, this.radRichTextBox.Document);
     
    for (int i = 0; i < 9; i++)
    {
        StyleDefinition headingStyle = this.radRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(i + 1)];
        headingStyle.ParagraphProperties.ListId = documentList.ID;
        headingStyle.ParagraphProperties.ListLevel = i;
    }

    I hope this helps.

    Regards,
    Petya
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. DevCraft banner
Back to Top